SpeechSynthesizer.AddLexicon(Uri, String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 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();
}
}
}
以下是词典文件 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>
注解
发音词典是单词或短语的集合及其发音,其中包括来自支持的拼音字母表中的字母和字符。 在应用程序中,可以使用字典为专用词汇指定自定义发音。
外部词典文件中指定的发音优先于语音合成器的内部词典或词典的发音。 但是,在使用、或方法创建的提示中,以内联方式指定的发音 AppendTextWithPronunciation AppendSsmlMarkup AppendSsml 优先于在任何词典中指定的发音。 内嵌发音仅适用于单词的单个匹配项。 有关详细信息,请参阅 词典和拼音字母表 。
您可以向一个对象添加多个词典 SpeechSynthesizer 。 对于参数,当前支持两个值 mediaType
:
值
application/pls+xml
指示词典符合 发音词典规范 (PLS) 版本 1.0。 这是要使用的首选格式。该值
application/vdn.ms-sapi-lex
指示词典格式是一种 Microsoft 专有格式的未压缩词典。 这是旧格式,建议使用上述 PLS 格式。