我正在使用语音合成器将文本转换为语音。我想使用自定义词典文件,所以我使用了msdn上推荐的 AddLexicon 方法
这是我的功能
public void ReadOut(string sentence)
{
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
synth.SelectVoiceByHints(gender: VoiceGender.Male, age: VoiceAge.Adult, voiceAlternate: 1, culture: CultureInfo.CreateSpecificCulture("en-US"));
synth.Rate = -2;
var fqn = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var uri = new Uri("file://" + fqn + "/CustomLexicon.pls");
synth.AddLexicon(uri, "application/pls+xml");
synth.Speak(sentence);
}
}
我的词典文件是
<?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>
但是,当我将“BLUE”传递给函数时,它仍然输出 BLUE 而不是 BLIP。我错过了什么吗?
注意:我确保 pls 文件存在于正确的位置,并且其内容已正确填充。