Handling issues with audio input for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

The speech recognizer raises the SpeechRecognizerAudioProblemOccurred()()() event when it encounters conditions that interfere with accurate recognition of speech input. If you use the Windows.Phone.Speech.Recognition.SpeechRecognizerUI class, the event is also raised when speech recognition occurs on the Did you say screen.

You can use a handler for the event to retrieve a description of the audio problem, such as too quiet, too loud, too noisy, or too fast. You may be able to use the description of the audio problem to take steps improve the conditions for recognition, for example to prompt a user to speak louder.

AudioProblemOccurred code example

The following example shows you how to register for the SpeechRecognizerAudioProblemOccurred()()() event and how to handle the event.

// Declare the SpeechRecognizerUI and SpeechSynthesizer objects at the class level.
SpeechRecognizerUI recoWithUI;
SpeechSynthesizer synth;

// Initialize the SpeechRecognizerUI and SpeechSynthesizer objects.
recoWithUI = new SpeechRecognizerUI();
synth = new SpeechSynthesizer();

// Register for the AudioProblemOccured event.
recoWithUI.Recognizer.AudioProblemOccurred += Recognizer_AudioProblemOccurred;

// Load the predefined dictation grammar and start recognition.
private async void Reco1_Click(object sender, RoutedEventArgs e)
{
  // Display text to prompt the user's input.
  recoWithUI.Settings.ListenText = "Trivia category?";

  // Give an example of ideal speech input.
  recoWithUI.Settings.ExampleText = " 'geography', 'movies', 'science' ";

  // Start recognition.
  SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
}

// Handle the AudioProblemOccurred event.
async void Recognizer_AudioProblemOccurred(SpeechRecognizer sender, SpeechAudioProblemOccurredEventArgs args)
{

  // If input speech is too quiet, prompt the user to speak louder.
  if (args.Problem == SpeechRecognitionAudioProblem.TooQuiet)
  {
    await synth.SpeakTextAsync("Try speaking louder");
  }
}

Other speech recognition errors and exceptions

There are many other speech recognition errors and exceptions that you may encounter when working with the feature. For more info, see Handling errors in speech apps for Windows Phone 8.

See Also

Other Resources

Speech recognition for Windows Phone 8

Speech for Windows Phone 8