nodejs认知服务语音SDK是否仍受支持?我知道如何为基于浏览器的sdk执行此操作,但是看来nodejs版本不起作用,它无法捕获任何麦克风输入。
值得注意的是,没有发布将AudioConfig.fromDefaultMicrophoneInput
用于nodejs的示例。 nodejs sdk与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
答案 0 :(得分:0)
对于此错误,Microsoft工程师对此here进行了解释。
这是由于默认的麦克风支持使用Web Audio API来 让人联想到麦克风流。节点环境不支持 这个。
作为一种解决方法,对于纯节点代码,您可以使用文件,push或pull 流以将音频输入语音识别引擎。
希望它会有所帮助:)