このトピックはまだ評価されていません - このトピックを評価する

読み込み済みの文法の管理による Windows Phone 8 の認識の最適化

2013/03/11

対象: Windows Phone 8 のみ

認識に使用する文法セットを読み込んだ後、アプリで SpeechGrammar.Enabled プロパティを true または false に設定することにより、認識処理でアクティブにする文法を管理することができます。既定の設定は true です。通常、認識処理のたびに文法の読み込みとアンロードを行うより、文法を 1 回読み込んで必要に応じてアクティブ化または非アクティブ化する方が効率的です。文法を読み込んでアンロードするよりも、SpeechGrammar.Enabled プロパティを設定する方が、必要なプロセッサ リソースが少なく、時間が短縮されます。

音声認識エンジンが音声入力に一致する語句を検索するのに必要なデータ容量を制限するため、認識用にアクティブにする文法の数を制限します。これにより、音声認識のパフォーマンスと精度が向上します。どの文法をアクティブにするかは、アプリが現在の認識処理のコンテキストで想定している語句に基づいて決定します。

たとえば、ユーザーが発言した色を表示することが現在のアプリ コンテキストであれば、動物の名前を認識するための文法をアクティブにする必要はありません。表示する色を把握する必要がある場合に、動物の名前を認識することは、アプリにとってほとんど意味がありません。

認識処理用にアクティブにする文法を決定するときは、認識処理のためにどのような語句を発音すればよいか、ユーザーが確実に理解できるよう準備が必要です。そうすれば、アクティブな文法にマッチング可能な語句をユーザーが発音する可能性が高まります。ユーザーが何を話せばよいかをプロンプトで指示するには、Windows.Phone.Speech.Recognition.SpeechRecognizerUISettings 列挙体の SpeechRecognizerUISettings.ExampleText および SpeechRecognizerUISettings.ListenText メンバーを使用します。この列挙体は、SpeechRecognizerUI.Settings プロパティを使用して設定できます。詳細については、「Windows Phone 8 のプロンプト、確認、不明瞭解消の選択肢の表示」を参照してください。

次の例は、ユーザーに果物、色、動物の名前を言うよう指示するアプリの抜粋です。この例では、アプリの該当部分に必要な文法を作成して読み込んでいます。各認識処理の前に、たとえばアプリが果物の名前を想定しているときは動物の名前が認識されないように、文法を選択的に有効または無効にします。その後、ユーザーに話すよう指示し、認識を開始する前にどのような語句が期待されているかをユーザーに知らせます。

private async void EnableDisable_Click(object sender, RoutedEventArgs e)
{
  // Initialize a SpeechRecognizerUI object.
  SpeechRecognizerUI recoWithUI = new SpeechRecognizerUI();

  // Create string arrays to use in grammars.
  string[] fruit = { "apple", "peach", "banana" };
  string[] colors = { "red", "green", "blue" };
  string[] animals = { "dog", "cat", "fish" };

  //Create list grammars from the string arrays and add them to the grammar set.
  //Grammars are enabled by default.
  recoWithUI.Recognizer.Grammars.AddGrammarFromList("fruitList", fruit);
  recoWithUI.Recognizer.Grammars.AddGrammarFromList("colorList", colors);
  recoWithUI.Recognizer.Grammars.AddGrammarFromList("animalList", animals);

  // RECOGNIZE FRUIT: Disable grammars for colors and animals. Only the fruit grammar is enabled.
  recoWithUI.Recognizer.Grammars["colorList"].Enabled = false;
  recoWithUI.Recognizer.Grammars["animalList"].Enabled = false;

  // Prompt the user to say a fruit.
  recoWithUI.Settings.ListenText = "Say a fruit";
  recoWithUI.Settings.ExampleText = " 'apple', 'peach', 'banana' ";

  // Load the grammar set and start recognition for fruits.
  SpeechRecognitionUIResult recoFruit = await recoWithUI.RecognizeWithUIAsync();

  // RECOGNIZE COLORS: Disable the fruit grammar, enable the color grammar. 
  // Only the color grammar is enabled.
  recoWithUI.Recognizer.Grammars["fruitList"].Enabled = false;
  recoWithUI.Recognizer.Grammars["colorList"].Enabled = true;

  // Prompt the user to say a color.
  recoWithUI.Settings.ListenText = "Say a color";
  recoWithUI.Settings.ExampleText = " 'red', 'green', 'blue' ";

  // Start recognition for colors.
  SpeechRecognitionUIResult recoColors = await recoWithUI.RecognizeWithUIAsync();

  // RECOGNIZE ANIMALS: Disable the color grammar, enable the animals grammar. 
  // Only the animals grammar is enabled.
  recoWithUI.Recognizer.Grammars["colorList"].Enabled = false;
  recoWithUI.Recognizer.Grammars["animalList"].Enabled = true;

  // Prompt the user to say an animal.
  recoWithUI.Settings.ListenText = "Say an animal";
  recoWithUI.Settings.ExampleText = " 'cat', 'dog', 'fish' ";

  // Start recognition for animals.
  SpeechRecognitionUIResult recoAnimals = await recoWithUI.RecognizeWithUIAsync();
}

この情報は役に立ちましたか。
(残り 1500 文字)
© 2013 Microsoft. All rights reserved.