XNA UK User Group

A helping hand for bedroom coders throughout the land.
in

RandomChaos

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:

synth.SpeakAsync("Hello, Welcome to the Random Chaos Generic X N A Speech Sample." +
                                " This sample is hosted by; the X N A U K User Group. Thanks " +
                                "to Leaf and Robin for letting me host my blog here and I hope " +
                                "you find my samples useful.");

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:

synth.SelectVoice("LH Michael");
synth.SelectVoice("LH Michelle");
synth.SelectVoice("Microsoft Sam");

I prefer "LH Michael", reminds me of Stephen Hawking and I think it's a little clearer than the other two.

I know, not the best chat in the world, but it's free lol

Published Jul 17 2008, 02:44 PM by Nemo Krad
Filed under: ,

Comments

 

Graphics Runner said:

Lol that's pretty cool. That Stephen Hawking voice really made my day.

July 17, 2008 5:50 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About Nemo Krad

Have been a professional developer since 1995. My skill set ranges from C/C++, VB6,MSSQL, Java Script, VB Script, HTML/ASP, Java, C#, ASP.NET as well as others. I started 3D and games development when the first release of XNA came out in December 2006 and have become addicted to it.