My PC Can Speak and Understand 26 Languages. And Yours?






4.60/5 (15 votes)
TTS and SR with Microsoft Server Speech Platform 10.2 for 26 languages

Introduction
If you are interested in computer text to speech (TTS) and speech recognition (SR), this little article is for you. In order to make the PC capable of speech and speech recognition, we need to install the Microsoft Server Speech Platform 10.2, its SDK and the Runtime Languages for TTS and SR you wish. Here are the links:
- Microsoft Speech Platform - Server Runtime (Version 10.2)
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bb0f72cb-b86b-46d1-bf06-665895a313c7&displaylang=en - Microsoft Speech Platform - Software Development Kit (SDK) (Version 10.2)
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21-90a294a5c9a4&displaylang=en - Microsoft Speech Platform - Server Runtime Languages (Version 10.2)
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=47ffd4e5-e682-4228-8058-dd895252a3c3&displaylang=en
NOTE: The Microsoft .NET Framework 3.5 is required to run the Microsoft Speech Platform. Starting from version 10.2 of the latter, the minimum OS required is Windows Vista. If you still have Windows XP, you can try to download an older version, may be 10.1.
After that, we need to create a Windows Form application and add the following reference to the project:
Assembly Microsoft.Speech
C:\Program Files\Microsoft Speech Platform SDK\Assembly\Microsoft.Speech.dll
Using the Code
Here is the code to enumerate the installed TTS voices:
// Create the TTS object and setup to fire the event 'SpeakCompleted'
SpeechSynthesizer _tts = new SpeechSynthesizer();
// Enumerate the installed Microsoft Server Speech TTS Voices
foreach (InstalledVoice voice in _tts.GetInstalledVoices())
{
listBox1.Items.Add(voice.VoiceInfo.Name);
}
Here is the code to speech text:
SoundPlayer _player = new SoundPlayer();
public void Speak(string text)
{
_player.Stream = new System.IO.MemoryStream();
_tts.SetOutputToWaveStream(_player.Stream);
_tts.SpeakAsync(text);
}
Here is the code to setup the speech recognition engine:
SpeechRecognitionEngine _sre = null;
// Create a simple grammar that recognizes the words
Choices words = new Choices();
// Add the words to be recognised
words.Add("red");
words.Add("green");
words.Add("blue");
words.Add("yellow");
words.Add("orange");
GrammarBuilder gb = new GrammarBuilder();
gb.Culture = new System.Globalization.CultureInfo(strCulture);
gb.Append(words);
// Create the actual Grammar instance, and then load it into the speech recognizer.
Grammar g = new Grammar(gb);
_sre.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
_sre.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
_sre.SetInputToDefaultAudioDevice();
_sre.RecognizeAsync(RecognizeMode.Multiple);
// Simple handler for the SpeechRecognized event.
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
// Add to the listbox the recognised speech
listBoxRecognisedWords.Items.Add(e.Result.Text);
}
Conclusion
Computer speech and speech recognition are interesting subjects. Nowadays, we can start interacting with the PC using voice. I remember the telefilms Start Trek and Knight Rider. There they could talk with the computer using the voice. These days, they are getting closer, but they are still far away. By the way, if the computer voice doesn't work well, ask Mr. Spock to fix it :-)