Good day.
I'm making a website, integrating the microsoft text-to-speech API. And I need to activate a function when the audio finishes playing it.
I've been doing a lot of research but I didn't find any method that really works.
Some "onend" event that works.
Do you know how I could achieve this? Thank you
startSpeakTextAsyncButton.addEventListener("click", function () {
startSpeakTextAsyncButton.disabled = true;
resultDiv.innerHTML = "";
synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);
synthesizer.speakTextAsync(
phraseDiv.value,
function (result) {
startSpeakTextAsyncButton.disabled = false;
resultDiv.innerHTML = "synthesis in process";
if (result.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
resultDiv.innerHTML = "synthesis finished";
} else if (result.reason === SpeechSDK.ResultReason.Canceled) {
resultDiv.innerHTML = "synthesis failed. Error detail: " + result.errorDetails + "\n";
}
synthesizer.close();
synthesizer = undefined;
},
function (err) {
startSpeakTextAsyncButton.disabled = false;
resultDiv.innerHTML = "Error: ";
resultDiv.innerHTML = err;
resultDiv.innerHTML = "\n";
window.console.log(err);
synthesizer.close();
synthesizer = undefined;
});
});