Pages

Tuesday, 3 July 2012

Speech in you Windows XNA Games

I found this while messing about with the media player in XNA, just noticed
there is some legacy code in the download from it :( Anyway, how to get speech
into your games, it's dead easy really, you just need to have .NET Framework 3.0
and you have all you need.

NOTE: You don't need XNA 3.0 for this just the .NET 3.0 Framework on
your system.

First off you need to add the System.Speech assembly to your project
references, then in your Game1.cs add the following:

using System.Speech.Synthesis;

and in your Game1 class add:

SpeechSynthesizer
synth = new
SpeechSynthesizer();

Now, all you have to do is call the synth.SpeackAsync() method passing the
text you want to have spoken. I used this:

This will use the default voice that is set up on your PC (see Control
Panel->Speech). But you can also access the other two voice types that ship
with the OS (XP, not sure about Vista). To do this try any one of these: