Please have a look at the below code
function longSentenceSpeak(text)
{
var url = "http://ift.tt/1E0UgLT"+finalString;
var url2 = "http://ift.tt/1GETcQi"+finalString;
var audio = document.getElementById('audio');
var source = document.getElementById('source');
source.src=url;
audio.load(); //call this to just preload the audio without playing
audio.play(); //call this to play the song right away
audio.onerror = function()
{
var url2 = "http://ift.tt/1cnSghc"+text;
var audio = document.getElementById('audio');
var source = document.getElementById('source');
source.src = url2;
audio.load(); //call this to just preload the audio without playing
audio.play(); //call this to play the song right away
};
}
Below is my HTML
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="scripts/TTS.js"></script>
<script>
function longText()
{
longSentenceSpeak("hello world ");
}
</script>
</head>
<body>
<audio id="audio">
<source id="source" src="" type="audio/mp3" />
</audio>
<div><button onclick="longText()">Click me</button></div>
</body>
</html>
However this gives the below error, even though it should handle it.
Failed to load resource: the server responded with a status of 404 (Not Found) (12:49:15:455 | error, network)
at http://ift.tt/1J6J809
What I want to do is, if this error occurred, I want to use var url2 instead of var url in function longSentenceSpeak(text). how can I do this?
Aucun commentaire:
Enregistrer un commentaire