SpeechSynthesizer.AddLexicon(Uri, String) 方法

定義

將字典加入至 SpeechSynthesizer 物件。

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

參數

uri
Uri

語彙資訊的位置。

mediaType
String

字典的媒體類型。 媒體類型不區分大小寫。

範例

下列範例示範新增和移除語彙的效果,其中包含 「blue」 一詞的自訂發音。 語彙會定義 「blue」 的發音,如 「bleep」。 載入語彙時,語音合成器會使用語彙中所定義的發音。

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.
        synth.SetOutputToDefaultAudioDevice();

        // 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();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

以下是 Blue.pls 檔案的語彙內容:

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

<lexicon version="1.0"
      xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
      alphabet="x-microsoft-ups" xml:lang="en-US">

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

</lexicon>

備註

發音語彙是單字或片語的集合,以及其發音,由支援的注音字母和字元所組成。 您可以使用語彙來指定應用程式中特製化詞彙的自訂發音。

外部語彙檔案中指定的發音優先于語音合成器的內部語彙或字典的發音。 不過,使用任何 AppendTextWithPronunciationAppendSsmlMarkupAppendSsml 方法所建立的提示內嵌指定的發音優先于任何語彙中所指定的發音。 內嵌發音僅適用于單一出現的單字。 如需詳細資訊,請參閱 Lexicons 和注音字母

您可以將多個語彙新增至 SpeechSynthesizer 物件。 參數目前支援兩個 mediaType 值:

  • application/pls+xml 表示語 匯符合發音語彙規格 (PLS) 1.0 版。 這是慣用的格式。

  • application/vdn.ms-sapi-lex 表示語彙格式為 Uncompressed Lexicon,這是Microsoft專屬格式。 這是舊版格式,建議您使用上述 PLS 格式。

適用於

另請參閱