SpeechSynthesizer.AddLexicon(Uri, String) SpeechSynthesizer.AddLexicon(Uri, String) SpeechSynthesizer.AddLexicon(Uri, String) Method


Adds a lexicon to the SpeechSynthesizer object.

 void AddLexicon(Uri ^ uri, System::String ^ mediaType);
public void AddLexicon (Uri uri, string mediaType);
member this.AddLexicon : Uri * string -> unit


Uri Uri Uri

The location of the lexicon information.

String String String

The media type of the lexicon. Media type values are not case sensitive.


The following example demonstrates the effect of adding and removing a lexicon that contains a custom pronunciation for the word "blue". The lexicon defines the pronunciation of "blue" to sound like "bleep". While the lexicon is loaded, the speech synthesizer uses the pronunciation defined in the lexicon.

using System;  
using System.Speech.Synthesis;  

namespace SampleSynthesis  
  class Program  
    static void Main(string[] args)  

      // Initialize a new instance of the SpeechSynthesizer.  
      using (SpeechSynthesizer synth = new SpeechSynthesizer())  

        // Configure the audio output.   

        // Speak the prompt.  
        synth.Speak("My favorite color is blue.");  

        // Add a lexicon that changes the pronunciation of "blue".  
        synth.AddLexicon(new Uri("C:\\test\\Blue.pls"), "application/pls+xml");  

        // Speak the prompt.  
        synth.Speak("My favorite color is blue.");  

        // Remove the lexicon.  
        synth.RemoveLexicon(new Uri("C:\\test\\Blue.pls"));  

        // Speak the prompt.  
        synth.Speak("My favorite color is blue.");  

      Console.WriteLine("Press any key to exit...");  

Following are the contents of the lexicon file Blue.pls:

<?xml version="1.0" encoding="UTF-8"?>  

<lexicon version="1.0"   
      alphabet="x-microsoft-ups" xml:lang="en-US">  

    <grapheme> blue </grapheme>  
    <phoneme> B L I P </phoneme>  



A pronunciation lexicon is a collection of words or phrases together with their pronunciations, which consist of letters and characters from a supported phonetic alphabet. You can use a lexicon to specify custom pronunciations for specialized vocabulary in your application.

Pronunciations specified in an external lexicon file take precedence over the pronunciations of the speech synthesizer's internal lexicon or dictionary. However, pronunciations specified inline in prompts created with any of the AppendTextWithPronunciation, AppendSsmlMarkup, or AppendSsml methods take precedence over pronunciations specified in any lexicon. Inline pronunciations apply only to a single occurrence of a word. See Lexicons and Phonetic Alphabets for more information.

You can add multiple lexicons to a SpeechSynthesizer object.Two values are currently supported for the mediaType parameter:

  • The value application/pls+xml indicates that the lexicon conforms to the Pronunciation Lexicon Specification (PLS) Version 1.0. This is the preferred format to use.

  • The value application/vdn.ms-sapi-lex indicates that the lexicon format is Uncompressed Lexicon, which is a Microsoft-proprietary format. This is a legacy format and we recommend that you use the PLS format described above.

Applies to

See also