如何在音频结束时获得'synthesisCompleted'?(Microsoft azure TTS)



我正在处理这个例子(https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/quickstart/javascript/browser/text-to-speech/index.html)使用Microsoft Azure语音服务将文本转换为语音
我想要的是在演讲结束时获得一个活动,这样我就可以做其他事情。现在,它向我发送了一个事件("synthesisCompleted"事件(,该事件本应在演讲结束时触发,但实际上它提前发送了(就像我不知道如何捕捉音频的末尾一样(。

有人能帮我吗?我不知道它是否有帮助,但我看到"speakTextAsync"中还有一个"stream"参数。

我终于找到了如何做到这一点。如果其他人也需要解决方案,这里是我的功能:

var SpeechSDK;
function textToSpeech(txt){
var player = new SpeechSDK.SpeakerAudioDestination();
player.onAudioEnd = function (_) {
##do something##
};
var audioConfig  = SpeechSDK.AudioConfig.fromSpeakerOutput(player);
const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(CONFIG.voiceSubKey, CONFIG.voiceLoc);  
speechConfig.speechSynthesisOutputFormat = "***";
speechConfig.speechSynthesisLanguage = CONFIG.voiceLan;
speechConfig.speechSynthesisVoiceName = CONFIG.voiceName;

var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);

const complete_cb = function (result) {
if (result.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
console.log("synthesis finished");
} else if (result.reason === SpeechSDK.ResultReason.Canceled) {
console.log("synthesis failed. Error detail: " + result.errorDetails);
}
synthesizer.close();
synthesizer = undefined;
};
const err_cb = function (err) {
window.console.log(err);
synthesizer.close();
synthesizer = undefined;
};
synthesizer.synthesisStarted  = function (s, e) {
console.log("Speech started");
};
synthesizer.speakTextAsync(txt,
complete_cb,
err_cb);

} 

if (!!window.SpeechSDK) {SpeechSDK = window.SpeechSDK;}

相关内容

  • 没有找到相关文章

最新更新