テキストを音声に変換するために音声シンセサイザーを使用しています。カスタム辞書ファイルを使用したかったので、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」を渡すと、BLIP ではなく BLUE が出力されます。何か不足していますか?
注:plsファイルが正しい場所に存在し、その内容が正しく入力されていることを確認しました.