【问题标题】:How can I get 'synthesisCompleted' at the very end of audio? (Microsoft azure TTS)如何在音频的最后获得“合成完成”? (微软天蓝色 TTS)
【发布时间】:2021-08-01 13:47:22
【问题描述】:

我正在研究这个使用的示例(https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/quickstart/javascript/browser/text-to-speech/index.html) Microsoft Azure 语音服务,以便将文本转换为语音。
我想要的是在语音结束时获得一个事件,以便我可以做其他事情。现在它向我发送了一个事件(“synthesisCompleted”),该事件应该在演讲结束时触发,但实际上它是更早发送的(就像我不知道如何捕捉音频的最后一样。

任何人都可以帮助我吗?我不知道它是否有帮助,但我看到“speakTextAsync”中还有一个“流”参数。

【问题讨论】:

  • 小更新:我发现我可以暂停和恢复定义var player = new SpeechSDK.SpeakerAudioDestination();的播放器,然后像player.pause()player.resume()一样调用它,但仍然无法找到结束的方法跨度>

标签: azure events text-to-speech voice


【解决方案1】:

我终于想通了。 如果其他人也需要解决方案,这就是我的功能:

    var SpeechSDK;

    function textToSpeech(txt){
      var player = new SpeechSDK.SpeakerAudioDestination();
      player.onAudioEnd = function (_) {
          ##do something##
        };
      var audioConfig  = SpeechSDK.AudioConfig.fromSpeakerOutput(player);
      const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(CONFIG.voiceSubKey, CONFIG.voiceLoc);  
      speechConfig.speechSynthesisOutputFormat = "***";
      speechConfig.speechSynthesisLanguage = CONFIG.voiceLan;
      speechConfig.speechSynthesisVoiceName = CONFIG.voiceName;
      
      var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);
      
      const complete_cb = function (result) {
        if (result.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
          console.log("synthesis finished");
        } else if (result.reason === SpeechSDK.ResultReason.Canceled) {
          console.log("synthesis failed. Error detail: " + result.errorDetails);
        }
        synthesizer.close();
        synthesizer = undefined;
      };
      const err_cb = function (err) {
        window.console.log(err);
        synthesizer.close();
        synthesizer = undefined;
      };

      synthesizer.synthesisStarted  = function (s, e) {
        console.log("Speech started");
      };
      synthesizer.speakTextAsync(txt,
        complete_cb,
        err_cb);
           
    } 
       
    if (!!window.SpeechSDK) {SpeechSDK = window.SpeechSDK;}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-08
    • 2023-04-06
    • 1970-01-01
    • 2023-04-06
    • 2020-10-08
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多