gpt4 book ai didi

azure - 如何在音频末尾获取 'synthesisCompleted'? (微软 azure TTS)

转载 作者:行者123 更新时间:2023-12-03 01:24:01 25 4
gpt4 key购买 nike


我正在研究这个使用的示例(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;}

关于azure - 如何在音频末尾获取 'synthesisCompleted'? (微软 azure TTS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67482595/

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