我正在使用语音合成器将文本转换为语音。我想使用自定义词典文件,因此我使用了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>
然而,当我通过&#34; BLUE&#34;对于该功能,它仍然输出BLUE而不是BLIP。我错过了什么吗?
注意:我确保pls文件存在于正确的位置,并且其内容已正确填充。
答案 0 :(得分:1)
这似乎是合成器的System.Speech实现中的一个错误,根据此处接受的答案:How do I use a lexicon with SpeechSynthesizer?