How do I use a lexicon with SpeechSynthesizer?

前端 未结 3 1095
逝去的感伤
逝去的感伤 2020-12-31 06:15

I\'m performing some text-to-speech and I\'d like to specify some special pronunciations in a lexicon file. I have ran MSDN\'s AddLexicon example verbatim, and it speaks the

3条回答
  •  孤独总比滥情好
    2020-12-31 06:16

    You can use System.Speech.Synthesis.SpeechSynthesizer.SpeakSsml() instead of a lexicon.

    This code changes pronunciation of "blue" to "yellow" and "dog" to "fish".

    SpeechSynthesizer synth = new SpeechSynthesizer();
    string text = "This is a blue dog";
    Dictionary phonemeDictionary = new Dictionary { { "blue", "jelow" }, { "dog", "fyʃ" } };
    foreach (var element in phonemeDictionary)
    {
       text = text.Replace(element.Key, "" + element.Key + "");
    }
    text = "" + text + "";
    synth.SpeakSsml(text);

提交回复
热议问题