次の方法で共有


オーディオ入力に関する問題を管理する

オーディオ入力品質によって発生する音声認識の精度に関する問題を管理する方法について説明します。

重要な API: SpeechRecognizerRecognitionQualityDegrading、SpeechRecognitionAudioProblem

オーディオ入力の品質を評価する

音声認識がアクティブな場合は、音声認識エンジンの RecognitionQualityDegrading イベントを使用して、1 つ以上のオーディオの問題が音声入力を妨げている可能性があるかどうかを判断します。 イベント引数 (SpeechRecognitionQualityDegradingEventArgs) は、オーディオ入力で検出された問題を説明する Problem プロパティを提供します。

認識は、バックグラウンド ノイズ、ミュートされたマイク、スピーカーの音量または速度の影響を受ける可能性があります。

ここでは、音声認識エンジンを構成し、RecognitionQualityDegrading イベントを監視し始めます。

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

音声認識エクスペリエンスを管理する

問題の プロパティで提供される説明を使用して、ユーザーが認識の条件を改善できるようにします。

ここでは、RecognitionQualityDegrading イベントに対する認識品質低下を検出するハンドラーを作成し、ボリュームレベルが低いかどうかを確認します。 次に、SpeechSynthesizer オブジェクトを使用して、ユーザーがより大きな声で話そうとすることを提案します。

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);
        });
    }
}
  • 音声での対話

サンプル