This is really easy and quick, but something that is handy. Getting speech synthesis to work under .NET 3.0 is really a breeze.
First, add a reference to System.Speech – this contains the managed speech API, it allows you to do recognition and synthesis extremely easily.
Next, add the following to an empty console application/button click event:
using (System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer())
{
synth.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Teen, 0);
synth.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Teen, 0);
synth.Speak("Hello world!");
}
And you’re done! That should have taken less than a minute if your references dialog didn’t take ages to load.
If you have Microsoft Anna (you have Windows Vista, Autoroute or Streets and Trips installed) then this will use that preferentially (that’s the SelectVoiceByHints line), otherwise it may use Microsoft Sam which sounds pretty bad but works well.
Permalink
3 Comments
Security Exception additional info
by jameselliot
at 05/24/2009 01:44:12
Hi,
I'm running Windows Vista Business x64 with VS2008. Just giving all the info.
James
I'm running Windows Vista Business x64 with VS2008. Just giving all the info.
James
Try UAC
by simon
at 06/03/2009 22:13:23
It may be that UAC affects this, however last time I checked it wasn't affected by it.
When I run this code I get a SecurityException. It is saying that the assembly does not allow partially trusted callers. It happens every time. I also put a try/catch block around the declaration but it doesn't even catch the exception. I'm at a loss here and I thought it was going to be easy. :-P
James