Microsoft语音识别+ nodejs

问题描述 投票:0回答:1

是否仍支持nodejs认知服务语音SDK?我知道如何为基于浏览器的sdk执行此操作,但是看来nodejs版本不起作用,它无法捕获任何麦克风输入。

[值得注意的是,没有发布示例将AudioConfig.fromDefaultMicrophoneInput用于nodejs。使用AudioConfig.fromStreamInput

,nodejs sdk可以正常工作

以下是相关代码:

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

javascript node.js azure
1个回答
0
投票

针对此错误,Microsoft工程师对此进行了解释here

这是由于默认麦克风支持使用Web Audio API来让人联想到麦克风流。节点环境不支持这个。

作为解决方法,对于纯节点代码,您可以使用文件,推入或拉入流以将音频输入语音识别引擎。

希望有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.