SpeechRecognitionAudioCaptureStateChangedEventArgs class

 

The SpeechRecognitionAudioCaptureStateChangedEventArgs class communicates the current state of the audio capture operation to the SpeechRecognizer.AudioCaptureStateChanged event.

Syntax

public class SpeechRecognitionAudioCaptureStateChangedEventArgs : EventArgs

The SpeechRecognitionAudioCaptureStateChangedEventArgs class has the following members.

Properties

Name

Description

State

Specifies where the application is in the audio capture process.

Example

The following code example prints status information to a TextBlock named StatusBar.

private static SpeechRecognizer SR;
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    var credentials = new SpeechAuthorizationParameters();
    credentials.ClientId = "<YOUR CLIENT ID>";
    credentials.ClientSecret = "<YOUR CLIENT SECRET>";
    SR = new SpeechRecognizer("en-US", credentials);
    SR.AudioCaptureStateChanged += SR_AudioCaptureStateChanged;
}

void SR_AudioCaptureStateChanged(SpeechRecognizer sender, 
      SpeechRecognitionAudioCaptureStateChangedEventArgs args)
{
    switch (args.State)
    {
        case SpeechRecognizerAudioCaptureState.Canceled:
            this.StatusBar.Text = "Operation cancelled.";
            break;
        case SpeechRecognizerAudioCaptureState.Cancelling:
            this.StatusBar.Text = "Cancelling capture operation...";
            break;
        case SpeechRecognizerAudioCaptureState.Complete:
            this.StatusBar.Text = "Audio capture complete.";
            break;
        case SpeechRecognizerAudioCaptureState.Initializing:
            this.StatusBar.Text = "Initializing audio capture...";
            break;
        case SpeechRecognizerAudioCaptureState.Listening:
            this.StatusBar.Text = "Listening...";
            break;
        case SpeechRecognizerAudioCaptureState.Thinking:
            this.StatusBar.Text = "Interpreting audio input...";
            break;
        default:
            this.StatusBar.Text = "Unknown capture state.";
            break;
    }    
}
var SR;
function pageLoaded() {
    var credentials = new Bing.Speech.SpeechAuthorizationParameters();
    credentials.clientId = "<YOUR CLIENT ID>";
    credentials.clientSecret = "<YOUR CLIENT SECRET>";
    SR = new Bing.Speech.SpeechRecognizer("en-US", credentials);

    SR.onaudiocapturestatechanged = SR_AudioCaptureStateChanged;
}

function SR_AudioCaptureStateChanged(sender, args) {
    switch (args.State) {
        case SpeechRecognizerAudioCaptureState.Canceled:
            this.StatusBar.Text = "Operation cancelled.";
            break;
        case SpeechRecognizerAudioCaptureState.Cancelling:
            this.StatusBar.Text = "Cancelling capture operation...";
            break;
        case SpeechRecognizerAudioCaptureState.Complete:
            this.StatusBar.Text = "Audio capture complete.";
            break;
        case SpeechRecognizerAudioCaptureState.Initializing:
            this.StatusBar.Text = "Initializing audio capture...";
            break;
        case SpeechRecognizerAudioCaptureState.Listening:
            this.StatusBar.Text = "Listening...";
            break;
        case SpeechRecognizerAudioCaptureState.Thinking:
            this.StatusBar.Text = "Interpreting audio input...";
            break;
        default:
            this.StatusBar.Text = "Unknown capture state.";
            break;
    }
}

A status field, as in this example, is one way to communicate application status to your users, but visual changes to the control or application window could accomplish the same thing.

Requirements

Minimum Supported Client

Windows 8

Required Extensions

Bing.Speech

Namespace

Bing.Speech