Bagikan melalui


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

RecognizedPhrase.Confidence Property

Gets a value, assigned by the recognizer, that represents the likelihood that a RecognizedPhrase matches a given input.

Namespace:  Microsoft.Speech.Recognition
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

'Declaration
Public ReadOnly Property Confidence As Single
    Get
'Usage
Dim instance As RecognizedPhrase
Dim value As Single

value = instance.Confidence
public float Confidence { get; }

Property Value

Type: System.Single
A relative measure of the certainty of correct recognition of a phrase. The value is from 0.0 to 1.0, for low to high confidence, respectively.

Remarks

Confidence scores do not indicate the absolute likelihood that a phrase was recognized correctly. Instead, confidence scores provide a mechanism for comparing the relative accuracy of multiple recognition alternates for a given input. This facilitates returning the most accurate recognition result. For example, if a recognized phrase has a confidence score of 0.8, this does not mean that the phrase has an 80% chance of being the correct match for the input. It means that the phrase is more likely to be the correct match for the input than other results that have confidence scores less than 0.8.

A confidence score on its own is not meaningful unless you have alternative results to compare against, either from the same recognition operation or from previous recognitions of the same input. The values are used to rank alternative candidate phrases returned by the Alternates property on RecognitionResult objects.

Confidence values are relative and unique to each recognition engine. Confidence values returned by two different recognition engines cannot be meaningfully compared.

A speech recognition engine may assign a low confidence score to spoken input for various reasons, including background interference, inarticulate speech, or unanticipated words or word sequences. If your application is using a SpeechRecognitionEngine instance, you can modify the confidence level at which speech input is accepted or rejected with one of the UpdateRecognizerSetting() methods.

The Alternates property of the RecognitionResult object contains an ordered collection of RecognizedPhrase objects, each of which is a possible match for the input to the recognizer. The alternates are ordered from highest to lowest confidence.

Examples

The following example shows a handler for a SpeechRecognitionEngine.SpeechRecognized or Grammar.SpeechRecognized event. The example shows information associated with the RecognitionResult object, some of which is derived from RecognizedPhrase. The handler displays confidence scores for a recognized phrase as well as for recognition alternates.

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

See Also

Reference

RecognizedPhrase Class

RecognizedPhrase Members

Microsoft.Speech.Recognition Namespace

RecognitionResult

RecognizedWordUnit