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.

Reference

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.

Share/Bookmark
Published Πέμπτη, 17 Σεπτεμβρίου 2009 1:13 πμ by jupiter
Filed under: , ,

Comments

# re: Text to Speech using C#

..thanks for sharing!!! :) ...

Πέμπτη, 17 Σεπτεμβρίου 2009 3:15 πμ by Panoylhs

# re: Text to Speech using C#

That's great but there is no support for Greek or multilinguality in general. So I guess it's partly great ;-)...

Πέμπτη, 17 Σεπτεμβρίου 2009 11:16 πμ by kpantos

# re: Text to Speech using C#

what about .net 2??

Πέμπτη, 17 Σεπτεμβρίου 2009 6:33 μμ by xdinos

# re: Text to Speech using C#

To xdinos: Use the win32 Speech API (SAPI). The COM interface you need is ISpVoice, which has similar methods as SpeechSynthesizer. Check here for more information: msdn.microsoft.com/.../ms720151%28VS.85%29.aspx

Πέμπτη, 17 Σεπτεμβρίου 2009 7:48 μμ by jupiter

# re: Text to Speech using C#

Ω ρε φίλε, είναι τέλειο !! Μιλάμε τα σπάει !! Πάω να το δοκιμάσω επιτόπου !!

Πέμπτη, 17 Σεπτεμβρίου 2009 8:12 μμ by solidus

# Speech Recognition with C# – Dictation and Custom grammar

Speech recognition using C# / .NET. Describe how to use DicationGrammar and custom grammar.

Δευτέρα, 1 Φεβρουαρίου 2010 1:28 μμ by Jupiter's Blog

# Silverlight 4 text-to-speech

Ο Μιχάλης Ζερβός είχε γράψει ένα ωραίο post για μετατροπή κειμένου σε ομιλία (text-to-speech) χρησιμοποιώντας

Τετάρτη, 24 Φεβρουαρίου 2010 6:01 μμ by Ψηφιακές
Πινελιές

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Submit