I am using speech synthesizer for converting text to speech. I wanted to use a custom lexicon file so I used the AddLexicon method as recommended on msdn
Here is my function
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);
}
}
and my lexicon file is
<?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>
However, when i pass "BLUE" to the function it still outputs BLUE instead of BLIP. Am I missing something?
Note : I made sure that the pls file exists in the right location and its contents are correctly populated.
This appears to be a bug in the System.Speech implementation of the synthesizer, as per the accepted answer here: How do I use a lexicon with SpeechSynthesizer?