Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SpeechSynthesizer.AddLexicon Method (Uri, String)


Adds a lexicon to the SpeechSynthesizer object.

Namespace:   System.Speech.Synthesis
Assembly:  System.Speech (in System.Speech.dll)

public void AddLexicon(
	Uri uri,
	string mediaType


Type: System.Uri

The location of the lexicon information.

Type: System.String

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

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/ 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.

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>


.NET Framework
Available since 3.0
Return to top
© 2017 Microsoft