【发布时间】:2019-12-22 07:16:57
【问题描述】:
我对 Azure 的语音 sdk 还很陌生,所以很可能我遗漏了一些明显的东西,如果是这种情况,我们深表歉意。
我一直在从事一个项目,我想将音频文件/流从一种语言翻译成另一种语言。当他们的整个对话都是用一种语言(全是西班牙语)时,它工作得很好,但是当我给它提供一个有英语和西班牙语的真实对话时,它就崩溃了。它试图将英语单词识别为西班牙语单词(因此它会将诸如“对不起”之类的内容转录为西班牙语)。
据我所知,您可以设置多种目标语言(要翻译成的语言),但只能设置一种语音识别语言。这似乎意味着它无法处理存在多种语言的对话(例如与翻译的电话)或说话者在语言之间切换的对话。有没有办法让它适用于多种语言,或者这只是微软尚未完全解决的问题?
这是我现在拥有的代码(它只是他们 github 上示例的轻微修改版本):
// pull in the required packages.
var sdk = require("microsoft-cognitiveservices-speech-sdk");
(function() {
"use strict";
module.exports = {
main: function(settings, audioStream) {
// now create the audio-config pointing to our stream and
// the speech config specifying the language.
var audioConfig = sdk.AudioConfig.fromStreamInput(audioStream);
var translationConfig = sdk.SpeechTranslationConfig.fromSubscription(settings.subscriptionKey, settings.serviceRegion);
// setting the recognition language.
translationConfig.speechRecognitionLanguage = settings.language;
// target language (to be translated to).
translationConfig.addTargetLanguage("en");
// create the translation recognizer.
var recognizer = new sdk.TranslationRecognizer(translationConfig, audioConfig);
recognizer.recognized = function (s, e) {
if (e.result.reason === sdk.ResultReason.NoMatch) {
var noMatchDetail = sdk.NoMatchDetails.fromResult(e.result);
console.log("\r\nDidn't find a match: " + sdk.NoMatchReason[noMatchDetail.reason]);
} else {
var str = "\r\nNext Line: " + e.result.text + "\nTranslations:";
var language = "en";
str += " [" + language + "] " + e.result.translations.get(language);
str += "\r\n";
console.log(str);
}
};
//two possible states, Error or EndOfStream
recognizer.canceled = function (s, e) {
var str = "(cancel) Reason: " + sdk.CancellationReason[e.reason];
//if it was because of an error
if (e.reason === sdk.CancellationReason.Error) {
str += ": " + e.errorDetails;
console.log(str);
}
//We've reached the end of the file, stop the recognizer
else {
recognizer.stopContinuousRecognitionAsync(function() {
console.log("End of file.");
recognizer.close();
recognizer = undefined;
},
function(err) {
console.trace("err - " + err);
recognizer.close();
recognizer = undefined;
})
}
};
// start the recognizer and wait for a result.
recognizer.startContinuousRecognitionAsync(
function () {
console.log("Starting speech recognition");
},
function (err) {
console.trace("err - " + err);
recognizer.close();
recognizer = undefined;
}
);
}
}
}());
【问题讨论】:
标签: speech-to-text microsoft-cognitive azure-cognitive-services