NodeJS STT ContinuousRecognitionAsync - NoMatch, InitialSilenceTimeout

Jatebo 1 Reputation point
2022-03-17T15:22:58.083+00:00

I am trying to set up STT in Node JS, and am having trouble with transcribing longer audio.

With the below code, I am able to transcribe audio from the Azure Samples data, however each time I try to use my own file, the text is not recognised- however if I run the same file through the short audio transcription, the first utterance / 15 seconds is recognised and returned.

I've tried to set a silence timeout in case this solved the problem, but this hasn't had any impact.

Also, with the below, the first attempt always returns an error before the transcription starts - how is best to avoid this?

(async function () {
    // <code>
    "use strict";

    var sdk = require("microsoft-cognitiveservices-speech-sdk");
    var fs = require("fs");


    var subscriptionKey = "MY_SUBSCRIPTION_KEY";
    var serviceRegion = "service region"
    var filename = "myAudioFile.wav";

    var pushStream = sdk.AudioInputStream.createPushStream();


    fs.createReadStream(filename)
        .on("data", function (arrayBuffer) {
            pushStream.write(arrayBuffer.slice());
        })
        .on("end", function () {
            pushStream.close();
        });


    console.log("Now recognizing from: " + filename);


    var audioConfig = sdk.AudioConfig.fromStreamInput(pushStream);
    var speechConfig = sdk.SpeechConfig.fromSubscription(
        subscriptionKey,
        serviceRegion
    );


    speechConfig.speechRecognitionLanguage = "en-US";

    speechConfig.setProperty(
        sdk.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs,
        "10000"
    );

    var recognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);


    let transcript = { result: [] };

    recognizer.startContinuousRecognitionAsync(
        (recognizer.recognized = (recognizer, event) => {
            try {
                const res = event.result;
                console.log(`RECOGNIZED:AZURE Reason=${sdk.ResultReason[res.reason]}`);
                transcript.result.push(res.text);
                console.log(transcript.result.join(" "));
            } catch (error) {
                console.log(`RECOGNIZED:AZURE ErrorDetails=${error.errorDetails}`);
            }
        })
    );
})();
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,061 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.