【问题标题】:How to stop Microsoft Cognitive TTS audio playing?如何停止 Microsoft Cognitive TTS 音频播放?
【发布时间】:2020-06-23 10:58:51
【问题描述】:

我正在使用来自https://github.com/Azure-Samples/cognitive-services-speech-sdk 的 Microsoft Cognitive Services Speech SDK 的 JavaScript 版本。

在调用 synthesizer.speakTextAsync 时,浏览器会播放音频。当音频太长时,我想停止音频播放,但找不到任何有关如何执行此操作的文档?

感谢任何帮助!

    synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, 
        SpeechSDK.AudioConfig.fromDefaultSpeakerOutput());
    
    synthesizer.speakTextAsync(
      inputText,
      result => {
        if (result) {
          console.log(JSON.stringify(rssesult));
         }
      },
      error => {
        console.log(error);
      }
    );

【问题讨论】:

    标签: text-to-speech microsoft-cognitive


    【解决方案1】:

    支持停止音频播放。

    您需要创建一个SpeechSDK.SpeakerAudioDestination() 对象并使用它来创建这样的audioConfig。

    var player = new SpeechSDK.SpeakerAudioDestination();
    var audioConfig  = SpeechSDK.AudioConfig.fromSpeakerOutput(player);
    var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);
    synthesizer.speakTextAsync(
    ...
    );
    

    然后你可以调用player.pause()player.resume()来暂停和恢复播放。

    您可以通过docsample 找到更多信息。

    【讨论】:

    • 谢谢!这回答了我的问题。
    • 这只会暂停和恢复音频,但不会在技术上停止
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多