Giving Computers a Voice
- Posted: Oct 31, 2006 at 2:20 AM
- 9,950 Views
- 29 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
| This article demonstrates how easy it is to enable managed applications to finally talk back using Microsoft's Speech API (SAPI). | |
|
Difficulty: Easy
Time Required:
1-3 hours
Cost: Free
Software: Visual Studio Express Editions
Hardware:
Download:
|
|
Most of us talk to our computers all the time. You wouldn't believe the things my wife says to her poor machine when something goes wrong. This article demonstrates how easy it is to enable managed applications to finally talk back using Microsoft's Speech API (SAPI). But don't worry: since you control what the application says, you can ensure it uses nicer language than my wife.
SAPI is the speech API that gives applications access to speech recognition and text-to-speech (TTS) engines. This article focuses on TTS. For TTS, SAPI takes text as input and uses the TTS engine to output that text as spoken audio. This is the same technology used by the Windows accessibility tool, Narrator. Every version of Windows since XP has shipped with SAPI and an English TTS engine.
TTS puts user's ears to work. It allows applications to send information to the user without requiring the user's eyes or hands. This is a very powerful output option that isn't often utilized on PCs.
Three steps are needed to use TTS in a managed application:
Since SAPI is a COM component, an interop DLL is needed to use it from a managed app. To create this, open the project in Visual Studio. Select the Project menu and click Add Reference. Select the COM tab, select "Microsoft Speech Object Library" in the list, and click OK. These steps add this reference to your project and create an Interop.SpeechLib.dll in the same folder as your executable. This interop DLL must always be in the same folder as your .exe to work correctly.
Include this namespace in your application. In C#, add "using SpeechLib;"; iIn VB, add “Imports SpeechLib”.
Speak()
Create a SpVoice object and call Speak():
Visual C#
SpVoice voice = new SpVoice();
voice.Speak("Hello World!", SpeechVoiceSpeakFlags.SVSFDefault);
Visual Basic
voice = New SpVoice
voice.Speak("Hello World!", SpeechVoiceSpeakFlags.SVSFDefault)
That's it! The downloads for this article are simple C# and VB.NET "hello world" samples to try out.
One of the best uses of TTS is for audio notifications. The System Monitor sample on coding4fun is a perfect candidate to be TTS-enabled. It informs a user when a particular system event has occurred through a message box, system tray balloon tip, or email. I'll use its extensible notification infrastructure to add TTS to this list.
First, create an interop DLL and add a reference to the namespace using the steps above.
Second, add this file to the SystemMonitor project:
SpeechNotifier.cs:
Visual C#
using System;
using SpeechLib;
namespace SystemMonitor.Notifiers
{
class SpeechNotifier : NotifierBase
{
public SpeechNotifier()
{
_voice = new SpVoice();
}
public override void Execute(string title, string message)
{
string text = "System monitor warning! " + title;
_voice.Speak(text, SpeechVoiceSpeakFlags.SVSFDefault);
}
private SpVoice _voice;
}
}
SpeechNotifier.vb:
Visual Basic
imports System
imports SpeechLib
Namespace SystemMonitor.Notifiers
Class SpeechNotifier Inherits NotifierBase
Public Sub New()
_voice = new SpVoice
End Sub Public Overrides Sub Execute(title As String, message As String)
String text = "System monitor warning! " + title;
_voice.Speak(text, SpeechVoiceSpeakFlags.SVSFDefault);
End Sub Private SpVoice _voice
End Sub End Class End Namespace
Third, add this line in the App.config file to any monitors you want to be spoken:
<notifier type="SystemMonitor.Notifiers.SpeechNotifier,SystemMonitor" />
For example:
<monitor runFrequency="00:04" type="SystemMonitor.Monitors.DiskSpaceMonitor,SystemMonitor">
<settings>
<setting name="driveLetter" value="C" />
<setting name="freeMegabytes" value="10000" />
</settings>
<notifiers>
<notifier type="SystemMonitor.Notifiers.SpeechNotifier,SystemMonitor" />
</notifiers>
</monitor>
This example will say "System monitor warning! Disk space low." when the space on c:\ drops below the specified value.
Cool project ideas
The TTS functionality on PCs is an under-used resource with much promise. Here are some more project ideas:
What's next?
This article outlines how you can use TTS on PCs today. But the real story is what's coming up.
WinFX will contain the fully managed API for speech. No more ugly COM interop. Developers will get all the benefits of a managed API and full intellisense support.
The default TTS engine on Windows Vista (formerly Windows code name "Longhorn") is much better than the default XP engine. Check out some of the resources below for updates as Windows Vista gets closer to shipping.
Resources
Here's some blogs from members of the Speech Components Group at Microsoft:
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Thank you this document helped me a lot..
Hello! Very interesting. Thank you.
cool totoring but were do u use speach to text
Hi!
There`s a way to do that but using a Spanish TTS?
Thanks!
This is a good tutorial, but is there any way to use the same funtionality on a web application. I have built one that works fine on a local server, but when deployed to the remote server, it has problems accessing the Speechlib in the BIN folder without creating an error.
Nevin
thank you very much but if you can send me how can i read from more languages specialy arabic and frensh.
my mail (elbanna23@yahoo.com)
thank you again
bye
It is not easy to find good and free Text to Speech libraries for your .NET application. Even the solution
I have worked on that but it does not have so good quality. For excellent quality there is aproject from AT&T. its free and you can use <a href="http://developeronline.blogspot.com/2008/01/text-to-speech-for-masses.html"> text-to-speech C#</a>
@Deepak Trama: If you know the text you're going to say, create a dictionary before hand and their lengths.
Without diving into the SAPI api, I couldn't tell you if it does or doesn't have that functionality. Sorry.
Hi,
I'm writing an app which generates a .wav file from some text.
I need to sync some pictures with this text and present it to the user as a slide show.
'Sync' is a relative term here, I need the pictures to appear some what close to the words when they are spoken.
Is there some way (a SAPI api) which will tell me where (duration in seconds) a particular word would occur in the generated audio file.
Any ideas?
My email is zodiac.seven@gmail.com
This is a good very good article. There seems to be quite a bit of information on TTS. But, can somebody help me with STT Speech-To-Text conversions? RichardMaliwatu@hotmail.com
i want to know that is it possible to convert voice to digital signal and then to identify the speaker...
if yes then plz provide me the C# code for voice recognition...
thank you!!
Thanks very much for this excellent tutorial.
Can you teach me how to choose other voices in c# ?
does SAPI supports multi languages like german,spanish.
hi
it was so interesting article.
pleas introduce me some more example about speech recognition.I need something simple with no grammer recognition. something that just understand one word.
thanks alot
amin_mhsn@yahoo.com
amin
Check out http://www.iSpeech.org/ The work is already done for you. Not to mention it uses good voices and it's free.
Thanks a lot for the information provided above
Easier than that complicated code above:
You can just have a textbox and a button, and on the button type:
Dim SAPI
SAPI = CreateObject("sapi.spvoice")
SAPI.Speak(TextBox1.Text)
and you can replace the Textbox1.Text to "Anything In parenthesis" to make SAPI say something specific when that button is clicked
@Mark, attempting to track this down as I'm not a SAPI expert.
Hi,
Is is possible to set an audio stream as an input to the SpeechRecognitionEngine, SpInProcRecognizer ?
This stream will NOT be a stream of fixed size. I will keep writing byte arrays to this stream one after the other.
Thanks in advance,
Mark
@Mark Yes. This is possible by implementing your own com object that implements the ISpStreamFormat interface. I don't know of any samples that demonstrate this precisely, though.
Hi,
Great tutorial. I wanted to know that can i use the british voice instead of american voice ? if yes then please let me know how ? I am using windows 7 and developing a web application on asp.net 3.5 in visual studio 2010.
Thanks in advance,
Chintan
good man ,good job,keep it up and give programmers those things which they dont know about
@יעל if I translated this correctly, "How can I change the tone of speech", Not sure you can change the voice programmatically.
[/urlWe sell the well-known[url= http://soccerfootballboots.com]soccer football boots on sale[/url].You can choose which you like,[url= http://soccerfootballboots.com]Nike football boots],[url= http://soccerfootballboots.com m]Adidas football boots[/url]are both hot sale, We sell[url=http://soccerfootballboots.com]football boots online[/url]large quantities. Welcome to our site http://soccerfootballboots.com
Thanks a lot, hope this will help me a lot
I get an error at the line where you create the new object: Abort During Order Evaluation: Incorrect Order Number
Awesome, much easier than the system.speech namespace! :)
Works well in websites
please how do i use speech to activate a command button click in vb 6?!i have downloaded SAPI 5.1. need help asap...
Remove this comment
Remove this thread
close