gpt4 book ai didi

text-to-speech - 如何停止 Microsoft Cognitive TTS 音频播放?

转载 作者:行者123 更新时间:2023-12-01 23:57:23 43 4
gpt4 key购买 nike

我正在使用来自 https://github.com/Azure-Samples/cognitive-services-speech-sdk 的 Microsoft 认知服务语音 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);
}
);

最佳答案

支持停止音频播放。

您需要创建一个 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()来暂停和恢复播放。

您可以从 doc 中找到更多信息和 sample .

关于text-to-speech - 如何停止 Microsoft Cognitive TTS 音频播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62523344/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com