Skip to content

Commit 190ee3b

Browse files
rizwan29rizwandr
authored andcommitted
fix: Chrome autoplay (#127)
* to support audio autoplay in google chrome * npm run autofix- changes Co-authored-by: null <[email protected]>
1 parent 5189d0b commit 190ee3b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: text-to-speech/synthesize.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ module.exports = function synthesize(options) {
5555
audio.crossOrigin = 'anonymous';
5656
audio.src = url + '/v1/synthesize?' + qs.stringify(pick(options, QUERY_PARAMS_ALLOWED));
5757
if (options.autoPlay !== false) {
58-
audio.play();
58+
var playPromise = audio.play();
59+
if (playPromise !== undefined) {
60+
playPromise
61+
.then(() => {
62+
// console.log("autoPlay promise resolved")
63+
})
64+
.catch(error => {
65+
throw new Error('Watson TextToSpeech: autoplay error:' + error);
66+
});
67+
}
5968
}
6069
return audio;
6170
};

0 commit comments

Comments
 (0)