SpeechRecognizer.RecognizeSpeechToTextAsync() method

Bing
 

The RecognizeSpeechToTextAsync() method starts a speech recognition session, which captures and interprets user speech, and then returns the results as a SpeechRecognitionResult object.

public IAsyncOperation<SpeechRecognitionResult> RecognizeSpeechToTextAsync()

Type: Bing.Speech.SpeechRecognitionResult

The result of the speech recognition session.

Exception Condition

Exception

Condition

System.InvalidOperationException

There is already a speech recognition operation in progress

--OR--

The user has not accepted the privacy statement.

--OR--

No microphone was found, or the microphone is disabled.

System.Exception HRESULT: 0xC00D36B4

The Audio extensions are not correctly defined in the Package.appxmanifest file. To correct this error, see How to: Enable a project for the Bing Speech Recognition Control.

The RecognizeSpeechToTextAsync() method starts a speech recognition session, interprets the speech input, and returns the result as a SpeechRecognitionResult object. A speech recognition session passes through four states, Initializing, Listening, Thinking, and Complete, which you can track through the SpeechRecognizer.AudioCaptureStateChanged event. Invoking the SpeechRecognizer.RequestCancelOperation() method causes two additional states, Cancelling and Cancelled.

You can interrupt speech recognition session in the Listening state by calling the SpeechRecognizer.StopListeningAndProcessAudio() method, or at any time with the RequestCancelOperation method.

System_CAPS_cautionCaution

When collecting speech results or intermediate results in a JavaScript application, quiet or unclear speech may cause the recognizeSpeechToTextAsync() method to return an error object in place of the result text. To maintain smooth program flow, verify that the result text is a string before attempting to read it. For more information, see How to: Add the Bing Speech Recognition Control to an application with a custom UI.

Example

The following example initializes a new SpeechRecognizer instance and then starts a speech recognition session, passing the result to SpeechRecognitionResult result.

var credentials = new Bing.Speech.SpeechAuthorizationParameters();
credentials.clientId = "<YOUR CLIENT ID>";
credentials.clientSecret = "<YOUR CLIENT SECRET>";
SR = new Bing.Speech.SpeechRecognizer("en-US", credentials);

var speechResult;
SR.recognizeSpeechToTextAsync().then(function (result) {
    if (typeof (result.text) == "string") {
        speechResult = result.text;
    }
})

Requirements

Minimum Supported Client

Windows 8

Required Extensions

Bing.Speech

Namespace

Bing.Speech