Skip to content

Commit

Permalink
fix: Chrome autoplay (#127)
Browse files Browse the repository at this point in the history
* to support audio autoplay in google chrome

* npm run autofix- changes


Co-authored-by: null <[email protected]>
  • Loading branch information
2 people authored and germanattanasio committed May 24, 2019
1 parent 5189d0b commit 190ee3b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion text-to-speech/synthesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ module.exports = function synthesize(options) {
audio.crossOrigin = 'anonymous';
audio.src = url + '/v1/synthesize?' + qs.stringify(pick(options, QUERY_PARAMS_ALLOWED));
if (options.autoPlay !== false) {
audio.play();
var playPromise = audio.play();
if (playPromise !== undefined) {
playPromise
.then(() => {
// console.log("autoPlay promise resolved")
})
.catch(error => {
throw new Error('Watson TextToSpeech: autoplay error:' + error);
});
}
}
return audio;
};

0 comments on commit 190ee3b

Please sign in to comment.