我正在使用 Microsoft 认知服务语音 SDK 的 JavaScript 版本https://github.com/Azure-Samples/cognitive-services-speech-sdk https://github.com/Azure-Samples/cognitive-services-speech-sdk.
当调用 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()
and player.resume()
暂停和恢复播放。
您可以从以下位置找到更多信息doc https://learn.microsoft.com/en-us/javascript/api/microsoft-cognitiveservices-speech-sdk/speakeraudiodestination?view=azure-node-latest and sample https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/8473970eac2a251ff2f9ba02c47688fa27f8a015/samples/js/browser/synthesis.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)