Gwo*_*wen 2 text-to-speech microsoft-cognitive
我正在使用来自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);
}
);
Run Code Online (Sandbox Code Playgroud)
小智 6
支持停止音频播放。
您需要创建一个SpeechSDK.SpeakerAudioDestination()对象并使用它来创建这样的 audioConfig。
var player = new SpeechSDK.SpeakerAudioDestination();
var audioConfig = SpeechSDK.AudioConfig.fromSpeakerOutput(player);
var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);
synthesizer.speakTextAsync(
...
);
Run Code Online (Sandbox Code Playgroud)
然后您可以调用player.pause()和player.resume()来暂停和恢复播放。