The following information is for the EMANT300

Analyse Source Code

Goto the Testspeech folder and start the IDE by clicking on the TestSpeech solution.

SpVoice Class

The SpVoice object brings the text-to-speech (TTS) engine capabilities to applications using SAPI automation. An application can create numerous SpVoice objects, each independent of and capable of interacting with the others. An SpVoice object, usually referred to simply as a voice, is created with default property settings so that it is ready to speak immediately.

Using SpeechLib;

using SpeechLib;

Allow unqualified reference to SpVoice. If you don't include this using directive, all references to the SpVoice object will have to full

Referencing Assemblies

Every project contains a References folder for identifying physical assemblies the code in the project uses. In order to use the SpVoice class, the program must reference the assembly Interop.SpeechLib.dll .



Program 1.1 Voice Source Code

SpVoice Voice = new SpVoice();
Voice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);
Voice.WaitUntilDone( -1 );

Create the SpVoice object

SpVoice Voice = new SpVoice();

An instance of SpVoice is created and called Voice. All future references to this object will use this name. Full description of the SpVoice Class can be found from the SDK website

http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/sapi.chm

Speak method

Voice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);

The Speak method places a text stream in the TTS engine's input queue and returns a stream number. It can be called synchronously or asynchronously. When called synchronously, the Speak method does not return until the text has been spoken; when called asynchronously, it returns immediately, and the voice speaks as a background process.

When synchronous speech is used in an application, the application's execution is blocked while the voice speaks, and the user is effectively locked out. This may be acceptable for simple applications, or those with no graphical user interface (GUI), but when sophisticated user interaction is intended, asynchronous speaking will generally be more appropriate.

int SpVoice.Speak(String Text,  [Flags As SpeechVoiceSpeakFlags = SVSFDefault])

Parameters

Text - The text to be spoken

Flags - Default value is SVSFDefault.

Return Value

An int variable containing the stream number. When a voice enqueues more than one stream by speaking asynchronously, the stream number is necessary to associate events with the appropriate stream.

Voice Activation & Annunciation Page 1 | 2 | 3 | 4 | 5