简体   繁体   中英

microsoft speech recognition + nodejs

Is the nodejs cognitive services speech sdk still supported? I know how to do this for the browser based sdk, but it looks like the nodejs version doesn't work, it doesn't capture any microphone input.

Notably, there are no examples publish that use AudioConfig.fromDefaultMicrophoneInput for nodejs. The nodejs sdk works perfectly fine with AudioConfig.fromStreamInput

Here's the relevant code:

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;
 });

I get an error saying: window is not defined

npm: https://www.npmjs.com/package/microsoft-cognitiveservices-speech-sdk

For this error, Microsoft engineers has an explain for it here .

It is due to the default microphone support uses the Web Audio API to conjure a microphone stream. The node environment doesn't support this.

As a workaround, for pure node code you can use a file, push or pull stream to get audio into the speech recognition engine.

Hope it helps: )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM