Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« 1000 Downloads of TipLight | Main | Kinect Skeleton Drawing Fun »
Thursday
Jan052012

A Computer that talks to itself…

Union Building

I’m still working on the Kinect voice controlled human painting program. First thing I need is a shorter name…

Today I added a feature I thought would be really cool. Voice response is one thing, but I also wanted the computer to talk back when I issued a command. Adding voice output to a C# program is a doddle.

First you add the System.Speech library to the references in your solution.

Then you add the speech synthesis namespace:

using System.Speech.Synthesis;

Now you can make your program speak:

SpeechSynthesizer speaker;

void setupSpeechOutput()
{
    speaker = new SpeechSynthesizer();
    speaker.Speak("Ready to Go");
}

This is the setup method for my speech output. Whenever you want your program to say something, just call the Speak method on the variable speaker. If you are worried about slowing things down you can use an asynchronous call to speak in the background while your program runs on. Works very well. In fact too well.

I had the program repeating the commands aloud and it worked wonderfully. I would say “Red” to select the red colour and the program would say “Red” back. Then commands started repeating, with the computer saying “Red” time after time. Took me a minute to figure out what was happening. Turns out that the computer is really good at recognizing computer speech. It would hear itself say the confirmation message and echo it, and so on. I added a timeout so that it ignores things for a second after a command and all is well now.

Reader Comments (3)

How does one get the .Speech library? It does not appear to be included with my copy of Visual Studio Professional...
January 8, 2012 | Unregistered CommenterJamz
Lazy to check, but if I remember properly there is a free (again and of course) SDK to download for that (before .net 3.0). Since then the SAPI is part of the .net framework, so in C# it is direct.

More info: http://msdn.microsoft.com/en-us/library/ee125663%28v=VS.85%29.aspx
January 8, 2012 | Unregistered CommenterEtienne
I think all you need is the sapi.dll. On my system it's located at

C:\windows\system32\speech\Common
January 9, 2012 | Unregistered CommenterDW

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.