Text to Speech using C#
Have you ever wanted to add voice to your application? Since .NET 3 came out, the process of doing it has become fairly easy, because you don’t have to deal with COM objects any more. System.Speech namespace provides a managed wrapper for the Speech API (SAPI). In this namespace you can find classes not only for Text-To-Speech but for Speech Recognition as well. All you have to do is add a reference to it from your project.
After that, converting a string to Speech is simple as that:
Remember to always Dispose (or use using() ) your SpeechSynthesizer instance when you don’t need it, because there are unmanaged resources that need to be freed. On the above example, i used the SpeechSynthesizer.Speak method which is synchronous. For most scenarios, asynchronous method SpeakAsync is better. SpeechSynthesizer gives you the power to pause, stop, resume, cancel an asynchronous call, etc. You can also do some neat things, like change the voice (provided that you have other voices installed on your machine):
or set the output to a .WAV file:
For a complete list of members and functions check MSDN.
EDIT: If you are interested in Speech Recognition with C# you can read this article.