In this series of articles, Part 1 covered using voice commands, Part 2 covered using voice diction, and Part 3 looked at their controls. Part 4 will cover making your application repeat what was dictated. There are two Controls that can be added, the Voice Text control or the Direct speech synthesis control. I will cover the Direct speech synthesis control because the Voice Text control is a simplified version of the Direct SS control.
As in the previous articles, I will only cover the basics, but give you the tools to do more.
What is required to do speech synthesis? Most systems already have the core synthesis engine loaded and do not require the SDK from Microsoft. However, as far as I can figure, the SDK adds to the functionality of this.
A Note on Voice Text Control: It is included in Windows 2K and XP, and also some versions of Visual Basic. The opperation of this control is simular to what is described below. Some of the Properties and Events have different names but use the same or similar Variables. If you’re interested in using the Voice Text Control, the same basics as explained here will work. But, remember that some of the properties like Pitch and VolumeLeft/Right and events like Wordposition do not exsist in Voice Text Control and are available only in the Direct SS control. Methods like AudioPause, AudioResume, and AudioReset are simply called Pause, Resume, and Reset, respectively, but operate exactly the same. Events like Visual do not have the time Stamp, timehi, and timeloas variables.
How do you use the Direct SS control? Add the Microsoft Direct Text-to-Speech component to your project. If you leave the Visible property as True, the lips will synchronise to the text spoken, although personally I prefer to set it to False.
The control does not require any initialisation, or any other form of settings to operate. To have the control read out some text, you simply call the Speak function with the text you want to be spoken.
When called, the method immediately returns control back to your application and speaks the words in text1.text. This is very important to know; if you have several text pieces you want to have spoken, you can queue them one after another, and simply respond to the events of the SS control.
DirectSS1.Speak Text1.Text DirectSS1.Speak Text2.Text DirectSS1.Speak Text3.Text
It is also advisable to disable the Voice Diction and Voice Commands when using the speak function because you may get unpredictable results.
After the control has completed speaking, it will call the Audiostop event. In this event, you can pick up that that the control has completed its task and taken the necessary actions—such as to re-enable the speak command button, moved on to the next page, and re-enabled voice diction.
Private Sub DirectSS1_AudioStop(ByVal hi As Long, ByVal lo As Long) Command1.Enabled = True VoiceDic.Unlock End Sub
While the control is busy, it will call the WordPosition event every time it starts a new word. You can use this event to synchronise the displaying of the words with the audio output.
Private Sub DirectSS1_WordPosition(ByVal hi As Long, _ ByVal lo As Long, _ ByVal byteoffset As Long) Text1.SelStart = byteoffset / 2 End Sub
Note: The byteoffset value is in Unicode and not ASCII, and requires a division of two to use it to set positions in a text box.
On the next page is a detailed list of the Controls Properties and methods.
In the Project download is a small VB application that uses the Direct SS control to repeat the text that has been dictated. It’s a simplified version of the Dictapad that is installed with the SDK, but it shows the simple inclusion of the Direct Speech Synthesiser control into any application.