我怎样才能在音频的最后得到 'synthesisCompleted' ? (微软天蓝色语音合成)
How can I get 'synthesisCompleted' at the very end of audio? (Microsoft azure TTS)
我正在处理这个使用 Microsoft Azure 语音服务将文本转换为语音的示例 (https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/quickstart/javascript/browser/text-to-speech/index.html)。
什么我想要的是在演讲结束时获得一个事件,以便我可以做其他事情。现在它向我发送了一个应该在演讲结束时触发的事件('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;}
我正在处理这个使用 Microsoft Azure 语音服务将文本转换为语音的示例 (https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/quickstart/javascript/browser/text-to-speech/index.html)。
什么我想要的是在演讲结束时获得一个事件,以便我可以做其他事情。现在它向我发送了一个应该在演讲结束时触发的事件('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;}