Skip to content

Commit 332ee78

Browse files
committed
TTS error logging, browser support notes and example
1 parent 7cef09f commit 332ee78

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Options:
7676
* voice - the desired playback voice's name - see .getVoices(). Note that the voices are language-specific.
7777
* autoPlay - set to false to prevent the audio from automatically playing
7878

79+
Relies on browser audio support: should work reliably in Chrome and Firefox on desktop and Android. Edge works with a little help. Safari and all iOS browsers do not seem to work yet.
7980

8081
## [`WatsonSpeech.SpeechToText`](http://watson-developer-cloud.github.io/speech-javascript-sdk/master/module-watson-speech_speech-to-text.html)
8182

examples/static/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ <h3>File Input</h3>
4343

4444
<h2>Text to Speech</h2>
4545
<ul>
46-
<li><a href="text-to-speech.html">Synthesize text, with pre-loaded token (compatible with Mobile Safari)</a></li>
46+
<li><a href="text-to-speech.html">Synthesize text</a></li>
47+
<li><a href="text-to-speech-preload.html">Synthesize text, with pre-loaded wav audio (works in Edge)</a></li>
4748
<li><a href="text-to-speech-custom-voice.html">Synthesize text w/ custom voice</a></li>
4849
</ul>
4950

examples/static/text-to-speech-custom-voice.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ <h2>Code for this demo:</h2>
5757
text: document.querySelector('#text').value,
5858
voice: document.querySelector('#voice').value,
5959
token: token
60+
}).on('error', function(err) {
61+
console.log('audio error: ', err);
6062
});
6163

6264
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Basic Example - Watson Text to Speech</title>
6+
<link rel="stylesheet" href="style.css" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<a href="/">&laquo; Examples</a>
12+
13+
<section>
14+
<h2>Basic Text to Speech Example</h2>
15+
<p><button id="button">Play Synthesized Text</button></p>
16+
</section>
17+
18+
<script src="bower_components/watson-speech/dist/watson-speech.js"></script>
19+
<!-- window.fetch pollyfill for IE/Edge & Older Chrome/FireFox -->
20+
<script src="bower_components/fetch/fetch.js"></script>
21+
22+
<h2>Code for this demo:</h2>
23+
<pre><code><script style="display: block;">
24+
// fetch the toke and create the audio element ahead of time
25+
var audio;
26+
fetch('/api/text-to-speech/token')
27+
.then(function(response) {
28+
return response.text();
29+
}).then(function (token) {
30+
audio = WatsonSpeech.TextToSpeech.synthesize({
31+
text: 'Hello from IBM Watson',
32+
token: token,
33+
autoPlay: false,
34+
accept: 'audio/wav'
35+
});
36+
37+
audio.on('error', function(err) {
38+
console.log('audio error: ', err);
39+
});
40+
});
41+
document.querySelector('#button').onclick = function () {
42+
audio.play();
43+
};
44+
</script></code></pre>
45+
</div>
46+
</body>
47+
</html>

examples/static/text-to-speech.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ <h2>Code for this demo:</h2>
3232
WatsonSpeech.TextToSpeech.synthesize({
3333
text: document.querySelector('#text').value,
3434
token: token
35+
}).on('error', function(err) {
36+
console.log('audio error: ', err);
3537
});
3638
});
3739
};

0 commit comments

Comments
 (0)