nodejs认知服务语音sdk仍然支持吗?我知道如何在基于浏览器的sdk中这样做,但是看起来nodejs版本不起作用,它不捕获任何麦克风输入。
值得注意的是,在nodejs中没有使用AudioConfig.fromDefaultMicrophoneInput
的示例发布。nodejs在AudioConfig.fromStreamInput
中非常好地工作。
以下是相关代码:
var speechsdk = require("microsoft-cognitiveservices-speech-sdk");
var subscriptionKey = ";)";
var serviceRegion = "eastus"; // e.g., "westus"
const speech_Config = speechsdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion, "en-US");
const audioConfig = speechsdk.AudioConfig.fromDefaultMicrophoneInput();
let speech_recognizer= new speechsdk.SpeechRecognizer(speech_Config, audioConfig);
speech_recognizer.recognizeOnceAsync(
function (result) {
console.log(result);
speech_recognizer.close();
speech_recognizer = undefined;
},
function (err) {
console.trace("err - " + err);
speech_recognizer.close();
speech_recognizer = undefined;
});
我说了一个错误:window is not defined
npm:https://www.npmjs.com/package/microsoft-cognitiveservices-speech-sdk
发布于 2019-09-24 17:51:10
对于这个错误,微软工程师有一个解释,这里。
这是因为默认的麦克风支持使用Web来调用麦克风流。节点环境不支持这一点。 作为解决办法,对于纯节点代码,您可以使用文件、推送或拉流将音频输入到语音识别引擎中。
希望它有帮助:)
https://stackoverflow.com/questions/58084122
复制