如何停止Microsoft Cognitive TTS音频播放? [英] How to stop Microsoft Cognitive TTS audio playing?

查看:14
本文介绍了如何停止Microsoft Cognitive TTS音频播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是https://github.com/Azure-Samples/cognitive-services-speech-sdk的Microsoft Cognitive Services Speech SDK的Java版本。

当调用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);
      }
    );

推荐答案

支持停止音频播放

您需要创建一个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中找到更多信息。

这篇关于如何停止Microsoft Cognitive TTS音频播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆