RecognitionResult.Alternates 属性

定义

获取语音识别器输入的可能匹配项的集合。

public:
 property System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::RecognizedPhrase ^> ^ Alternates { System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::RecognizedPhrase ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.RecognizedPhrase> Alternates { get; }
member this.Alternates : System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.RecognizedPhrase>
Public ReadOnly Property Alternates As ReadOnlyCollection(Of RecognizedPhrase)

属性值

识别备用项的只读集合。

示例

下面的示例演示事件的 SpeechRecognized 处理程序以及有关关联的 RecognitionResult一些信息。

// Handle the SpeechRecognized event.
void SpeechRecognizedHandler(object sender, SpeechRecognizedEventArgs e)
{
  if (e.Result == null) return;

  // Add event handler code here.

  // The following code illustrates some of the information available
  // in the recognition result.
  Console.WriteLine("Grammar({0}), {1}: {2}",
    e.Result.Grammar.Name, e.Result.Audio.Duration, e.Result.Text);

  // Display the semantic values in the recognition result.
  foreach (KeyValuePair<String, SemanticValue> child in e.Result.Semantics)
  {
    Console.WriteLine(" {0} key: {1}",
      child.Key, child.Value.Value ?? "null");
  }
  Console.WriteLine();

  // Display information about the words in the recognition result.
  foreach (RecognizedWordUnit word in e.Result.Words)
  {
    RecognizedAudio audio = e.Result.GetAudioForWordRange(word, word);
    Console.WriteLine(" {0,-10} {1,-10} {2,-10} {3} ({4})",
      word.Text, word.LexicalForm, word.Pronunciation,
      audio.Duration, word.DisplayAttributes);
  }

  // Display the recognition alternates for the result.
  foreach (RecognizedPhrase phrase in e.Result.Alternates)
  {
    Console.WriteLine(" alt({0}) {1}", phrase.Confidence, phrase.Text);
  }
}

注解

识别 Alternates 按其 Confidence 属性的值排序。 给定短语的置信度值指示短语与输入匹配的概率。 具有最高置信度值的短语是最有可能与输入匹配的短语。

应单独计算每个 Confidence 值,而不引用其他 Alternates值的置信度值。 继承RecognizedPhrase的属性RecognitionResult提供有关具有最高置信度分数的短语的详细信息。

集合 Alternates 的一个用途是自动更正错误。 例如,在设计目录对话框时,应用程序可能会提示用户检查应用程序是否具有识别事件的正确信息,如“你说'Anna'?”如果用户说“否”,则应用程序可以查询用户是否有任何具有足够 Confidence 高分数的备用项。

适用于

另请参阅