SpeechRecognitionAudioCaptureStateChangedEventArgs.State property

 

The State property specifies where the application is in the audio capture process.

Syntax

public SpeechRecognizerAudioCaptureState State { get; }

Property Value

Type: Bing.Speech.SpeechRecognizerAudioCaptureState

An enumeration value indicating the current state of the audio capture process.

Remarks

You can make changes to the UI of your application or custom speech control, based on the value of this property, to show progress to the user.

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

Requirements

Minimum Supported Client

Windows 8

Required Extensions

Bing.Speech

Namespace

Bing.Speech