Share via


RecognizedPhrase.Confidence 属性

定义

获取识别器分配的值,此值表示 RecognizedPhrase 与给定输入匹配的可能性。

public:
 property float Confidence { float get(); };
public float Confidence { get; }
member this.Confidence : single
Public ReadOnly Property Confidence As Single

属性值

对正确识别语法的确定性的相对度量。 该值分别为从 0.0 到 1.0,从低到高置信。

示例

以下示例演示 、 SpeechRecognizer.SpeechRecognizedGrammar.SpeechRecognized 事件的处理程序SpeechRecognitionEngine.SpeechRecognized。 该示例显示与 RecognitionResult 对象关联的信息,其中一些信息派生自 RecognizedPhrase。 处理程序显示已识别短语的置信度分数,以及识别替代项的置信度分数。

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("Recognition result summary:");  
  Console.WriteLine(  
    "  Recognized phrase: {0}\n" +   
    "  Confidence score {1}\n" +   
    "  Grammar used: {2}\n",   
    e.Result.Text, e.Result.Confidence, e.Result.Grammar.Name);  

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

  // Display information about the words in the recognition result.  
  Console.WriteLine("  Word summary: ");  
  foreach (RecognizedWordUnit word in e.Result.Words)  
  {  
    Console.WriteLine(  
      "    Lexical form ({1})" +  
      " Pronunciation ({0})" +  
      " Display form ({2})",  
      word.Pronunciation, word.LexicalForm, word.DisplayAttributes);  
  }  

  // Display information about the audio in the recognition result.  
  Console.WriteLine("  Input audio summary:\n" +  
    "    Candidate Phrase at:       {0} mSec\n" +  
    "    Phrase Length:             {1} mSec\n" +  
    "    Input State Time:          {2}\n" +  
    "    Input Format:              {3}\n",  
    e.Result.Audio.AudioPosition,  
    e.Result.Audio.Duration,  
    e.Result.Audio.StartTime,  
    e.Result.Audio.Format.EncodingFormat);  

  // Display information about the alternate recognitions in the recognition result.  
  Console.WriteLine("  Alternate phrase collection:");  
  foreach (RecognizedPhrase phrase in e.Result.Alternates)  
  {  
    Console.WriteLine("    Phrase: " + phrase.Text);  
    Console.WriteLine("    Confidence score: " + phrase.Confidence);  
  }  
}  

注解

置信度分数并不指示正确识别短语的绝对可能性。 相反,置信度分数提供了一种机制,用于比较给定输入的多个识别替代项的相对准确性。 这有助于返回最准确的识别结果。 例如,如果识别的短语的置信度分数为 0.8,这并不意味着该短语有 80% 的几率成为输入的正确匹配项。 这意味着,与置信度分数低于 0.8 的其他结果相比,该短语更有可能是输入的正确匹配项。

置信度分数本身就没有意义,除非有要比较的替代结果(来自同一识别操作或以前对同一输入的识别结果)。 这些值用于对 对象的 属性RecognitionResult返回Alternates的备用候选短语进行排名。

置信度值是相对的,并且是每个识别引擎的唯一值。 无法对两个不同识别引擎返回的置信度值进行有意义的比较。

语音识别引擎可能会出于各种原因为语音输入分配低置信度分数,这些原因包括背景干扰、无法解释的语音或意外字词或单词序列。 如果应用程序使用 SpeechRecognitionEngine 实例,则可以使用方法之一 UpdateRecognizerSetting 修改接受或拒绝语音输入的置信度。 由 SpeechRecognizer管理的共享识别器置信度阈值与用户配置文件相关联,并存储在 Windows 注册表中。 应用程序不应将共享识别器属性的更改写入注册表。

对象的 Alternates 属性 RecognitionResult 包含对象的有序集合 RecognizedPhrase ,其中每个对象都可能与识别器输入匹配。 替换选项按置信度从高到低的顺序排序。

适用于

另请参阅