It works fine. But it can only speak with the native system language and voice. The API call “window.speechSynthesis.getVoices()” returns an empty list on PlayCanvas. But it runs correct out of PlayCanvas. Any idea what went wrong?
Below is my code:
pc.script.create('SpeechTest', function (app) {
// Creates a new SpeechTest instance
var SpeechTest = function (entity) {
this.entity = entity;
};
SpeechTest.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
this.speak("It will automatically generate a wav file which you can easily get with an HTTP request through any");
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
},
speak: function(phrase) {
if(phrase === "") return;
var speech = new SpeechSynthesisUtterance(phrase);
var voices = window.speechSynthesis.getVoices();
speech.voice = voices.filter(function(voice) { return voice.name == 'Google UK English Male'; })[0];
window.speechSynthesis.speak(speech);
}
};
return SpeechTest;
});