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.