SrgsToken.Pronunciation Property


Gets or sets the string that defines the pronunciation for the token.

 property System::String ^ Pronunciation { System::String ^ get(); void set(System::String ^ value); };
public string Pronunciation { get; set; }
member this.Pronunciation : string with get, set
Public Property Pronunciation As String

Property Value

Returns a string containing phones from the phonetic alphabet specified in PhoneticAlphabet.


An attempt is made to set Pronunciation to null.

An attempt is made to assign an empty string to Pronunciation.


The grammar in the following example contains slang words and also has an uncommon word: "whatchamacallit". Adding a custom, inline pronunciation using the Pronunciation property of the SrgsToken class can improve the accuracy of recognition for the word "whatchamacallit" as well as for the entire phrase that contains it. The example uses phones from the Microsoft Universal Phone Set (UPS) to define the custom pronunciations.

using System;  
using System.Speech.Recognition;  
using System.Speech.Recognition.SrgsGrammar;  
namespace SampleRecognition  
  class Program  
    static void Main(string[] args)  
    // Initialize an instance of the in-process recognizer.  
      using (SpeechRecognitionEngine recognizer =  
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))  
        // Build the SrgsOneOf objects with alternative choices for the slang phrase.  
        SrgsOneOf gimme = new SrgsOneOf(  
          new string[] { "give me", "gimme", "hand me", "ha'me" });  
        SrgsOneOf the = new SrgsOneOf(new string[] { "the", "duh" });  
        // Build the one-of element that contains the pronunciation.  
        SrgsItem thing = new SrgsItem("thingamajig");  
        SrgsItem whatcha = new SrgsItem();  
        SrgsToken callit = new SrgsToken("whatchamacallit");  
        callit.Pronunciation = "W AE T CH AE M AE K AA L IH T";  
        SrgsOneOf what = new SrgsOneOf(new SrgsItem[] {thing, whatcha});  
        // Create the rule from the SrgsOneOf objects.  
        SrgsRule slangRule = new SrgsRule("slang", gimme, the, what);  
        // Build an SrgsDocument object from the rule and set the phonetic alphabet.  
        SrgsDocument tokenPron = new SrgsDocument(slangRule);  
        tokenPron.PhoneticAlphabet = SrgsPhoneticAlphabet.Ups;  
        // Create a Grammar object from the SrgsDocument and load it to the recognizer.  
        Grammar g_Slang = new Grammar(tokenPron);  
        g_Slang.Name = ("Slang Pronunciation");  
        // Configure recognizer input.  
        // Attach a handler for the SpeechRecognized event.  
        recognizer.SpeechRecognized +=   
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        // Start asynchronous recognition.  
        Console.WriteLine("Starting asynchronous recognition...");  
        // Keep the console window open.  
    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
      Console.WriteLine("Recognized phrase: " + e.Result.Text);  
      Console.WriteLine("Confidence: " + e.Result.Confidence);  
      Console.WriteLine("  Word summary: ");  
      foreach (RecognizedWordUnit word in e.Result.Words)  
          "    Lexical form ({1})" +  
          " Pronunciation ({0})" +  
          " Confidence ({2})",  
          word.Pronunciation, word.LexicalForm, word.Confidence);  


Phones are letters or symbols that describe the sounds of speech. System.Speech supports three phonetic alphabets for specifying custom pronunciations: the Universal Phone Set (UPS), the Speech API (SAPI) Phone set, and the International Phonetic Alphabet (IPA). The phones specified in Pronunciation must match the phonetic alphabet specified in PhoneticAlphabet. See Lexicons and Phonetic Alphabets for more information.

The phones specified in Pronunciation indicate how the contents of Text should be pronounced for successful recognition. The speech recognition engine uses the pronunciation specified in Pronunciation to match speech input and returns the string contained by Text in the recognition result.

If the phones are not space-delimited or the specified string contains an unrecognized phone, the recognition engine does not recognize the specified pronunciation as a valid pronunciation of the word contained by Text.

Pronunciations specified in Pronunciation take precedence over pronunciations specified in lexicons associated with a grammar or a recognition engine. Also, the pronunciation in the Pronunciation property applies only to the single occurrence of the word or phrase contained by Text.

Applies to

See also