SpeechRecognitionResult.GetAlternates(int) method

Bing
 

The GetAlternates(int) method returns the list of alternate interpretations of a speech recognition attempt.

public IReadOnlyList<SpeechRecognitionResult> GetAlternates(int maxAlternates)

maxAlternates

Type: System.Int

The maximum number of alternates to return.

Type: System.Collections.Generic.IReadOnlyList<Bing.Speech.SpeechRecognitionResult>

A list of up to maxAlternates alternate speech recognition results.

When a SpeechRecognizer finishes analyzing a speech session, it creates an IReadOnlyList of possible interpretations as SpeechRecognitionResult objects and ranks them in order of confidence. The SpeechRecognitionResult object with the highest TextConfidence value is ranked as item [0] in the list and is returned by the SpeechRecognizer.RecognizeSpeechToTextAsync() method. The GetAlternates(int) method gets the list of these alternate results.

In cases where no interpretation meets the minimum confidence threshold, the list of alternates will consist of a single SpeechRecognitionResult object with a Text value of null and a TextConfidence value of SpeechRecognitionConfidence.Rejected.

Invoking the GetAlternates(int) method on a primary SpeechRecognitionResult object or any member of the associated list of alternates will return the same result.

Example

The following example gets the alternates from a SpeechRecognitionResult, and then writes the Text and TextConfidence values to a drop down list named ResultChooser.

// Set maxAlternates.
var maxAlternates = 5;

// Get a speech recognition result from SpeechRecognizer SR.
SR.recognizeSpeechToTextAsync()
     .then(
         function (result) {
             if (typeof (result.text) == "string") {
                 // Write the alternate results to <option> elements.
                 var alternates = result.getAlternates(maxAlt);
                 if (alternates.length > 1) {
                     for (var i = 0; i < alternates.length; i++) {
                         var opt = document.createElement("option");
                         var tc = alternates[i].textConfidence.toString();
                         opt.innerHTML = window.toStaticHtml(alternates[i].text + " -- " + tc);

                         // Add the <option> elements to ResultChooser.
                         document.getElementById('ResultChooser').appendChild(opt);
                     }
                 }
             }
         }
      )

Requirements

Minimum Supported Client

Windows 8

Required Extensions

Bing.Speech

Namespace

Bing.Speech

Show: