Gestire i problemi relativi all'input audioManage issues with audio input

Scopri come gestire i problemi relativi alla precisione del riconoscimento vocale causati dalla qualità dell'input audio.Learn how to manage issues with speech-recognition accuracy caused by audio-input quality.

API importanti : SpeechRecognizer, RecognitionQualityDegrading, SpeechRecognitionAudioProblemImportant APIs : SpeechRecognizer, RecognitionQualityDegrading, SpeechRecognitionAudioProblem

Valutare la qualità di input audioAssess audio-input quality

Quando il riconoscimento vocale è attivo, usare l'evento RecognitionQualityDegrading del riconoscimento vocale per determinare se uno o più problemi audio potrebbero interferire con l'input vocale.When speech recognition is active, use the RecognitionQualityDegrading event of your speech recognizer to determine whether one or more audio issues might be interfering with speech input. L'argomento Event ( SpeechRecognitionQualityDegradingEventArgs) fornisce la proprietà problem , che descrive i problemi rilevati con l'input audio.The event argument ( SpeechRecognitionQualityDegradingEventArgs) provides the Problem property, which describes the issues detected with the audio input.

Il riconoscimento può essere influenzato da troppo rumore di fondo, da un microfono disattivato e dal volume o dalla velocità degli altoparlanti.Recognition can be affected by too much background noise, a muted microphone, and the volume or speed of the speaker.

Qui viene configurato un riconoscimento vocale e viene avviata l'attesa dell'evento RecognitionQualityDegrading .Here, we configure a speech recognizer and start listening for the RecognitionQualityDegrading event.

private async void WeatherSearch_Click(object sender, RoutedEventArgs e)
{
    // Create an instance of SpeechRecognizer.
    var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer();

    // Listen for audio input issues.
    speechRecognizer.RecognitionQualityDegrading += speechRecognizer_RecognitionQualityDegrading;

    // Add a web search grammar to the recognizer.
    var webSearchGrammar = new Windows.Media.SpeechRecognition.SpeechRecognitionTopicConstraint(Windows.Media.SpeechRecognition.SpeechRecognitionScenario.WebSearch, "webSearch");


    speechRecognizer.UIOptions.AudiblePrompt = "Say what you want to search for...";
    speechRecognizer.UIOptions.ExampleText = "Ex. 'weather for London'";
    speechRecognizer.Constraints.Add(webSearchGrammar);

    // Compile the constraint.
    await speechRecognizer.CompileConstraintsAsync();

    // Start recognition.
    Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync();
    //await speechRecognizer.RecognizeWithUIAsync();

    // Do something with the recognition result.
    var messageDialog = new Windows.UI.Popups.MessageDialog(speechRecognitionResult.Text, "Text spoken");
    await messageDialog.ShowAsync();
}

Gestire l'esperienza di riconoscimento vocaleManage the speech-recognition experience

Utilizzare la descrizione fornita dalla proprietà problem per consentire all'utente di migliorare le condizioni per il riconoscimento.Use the description provided by the Problem property to help the user improve conditions for recognition.

Qui viene creato un gestore per l'evento RecognitionQualityDegrading che controlla un livello di volume basso.Here, we create a handler for the RecognitionQualityDegrading event that checks for a low volume level. Usiamo quindi un oggetto SpeechSynthesizer per suggerire all'utente di parlare a voce più alta.We then use a SpeechSynthesizer object to suggest that the user try speaking louder.

private async void speechRecognizer_RecognitionQualityDegrading(
    Windows.Media.SpeechRecognition.SpeechRecognizer sender,
    Windows.Media.SpeechRecognition.SpeechRecognitionQualityDegradingEventArgs args)
{
    // Create an instance of a speech synthesis engine (voice).
    var speechSynthesizer =
        new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

    // If input speech is too quiet, prompt the user to speak louder.
    if (args.Problem == Windows.Media.SpeechRecognition.SpeechRecognitionAudioProblem.TooQuiet)
    {
        // Generate the audio stream from plain text.
        Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream;
        try
        {
            stream = await speechSynthesizer.SynthesizeTextToStreamAsync("Try speaking louder");
            stream.Seek(0);
        }
        catch (Exception)
        {
            stream = null;
        }

        // Send the stream to the MediaElement declared in XAML.
        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
        {
            this.media.SetSource(stream, stream.ContentType);
        });
    }
}

EsempiSamples