Search code examples
javascriptspeech-recognitionspeech-to-textazure-cognitive-services

How to stop Microsoft cognitive-services-speech-sdk-js to stop listening manually?


I've implemented a Speech to Text conversion using Cognitive Services. I need it to stop listening after staying active for some specific time.

In C# version of the SDK, there is a method to make it stop listening as specified here. Sample - // Stops recognition. await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);

I was looking similar method in JavaScript sdk but couldn't find any. So is there any way to make it stop listening?

EDIT - Adding my code sample-

var recognizer = new scope.SDK.SpeechRecognizer(speechConfig, audioConfig);
recognizer.recognizeOnceAsync(function (result) {
    console.log(result.text)
})

I need it to stop it even while it is listening to something.

Thanks.


Solution

  • recognizer.stopContinuousRecognitionAsync() is the method you're looking for.

    https://learn.microsoft.com/en-us/javascript/api/microsoft-cognitiveservices-speech-sdk/speechrecognizer?view=azure-node-latest#stopcontinuousrecognitionasync-------void---e--string-----void-