首页 > 解决方案 > Microsoft azure“文本到语音”javascript,onend 事件

问题描述

再会。

我正在制作一个网站,集成了 microsoft text-to-speech API。当音频播放完毕时,我需要激活一个功能。

我一直在做很多研究,但我没有找到任何真正有效的方法。

一些有效的“onend”事件。

你知道我怎么能做到这一点吗?谢谢

    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;
          });

        });

标签: javascriptazuretext-to-speech

解决方案


推荐阅读