Click here to Skip to main content
11,716,249 members (90,121 online)
Click here to Skip to main content

Using Text to Voice Interfaces

, 13 Sep 2002 129.6K 4.7K 56
Rate this:
Please Sign up or sign in to vote.
Using Microsoft Text to Voice Interfaces in MFC

Sample Image

Introduction

This article guides you to create a simple COM client using MFC, and following the same method we can create clients for any Component when a type library file (.tlb) is available.

Note: On any machines with Windows 2000 Installed check for a "Speech" folder under C:\WINNT. This folder contains all the necessary components to call speech engine.

So to start, fire up the VC++ 6.0 IDE and then select File->New, select the MFC AppWizard [exe] and Enter "SpeakText" as the Project name and save it in the required location. Select "Dialog Base" option and uncheck the "Document/View Architecture".

Design the user interface dialog as shown in the figure above using resource editor and name your dialog and its controls accordingly.

Note: In edit control properties, on the Styles tab select "Multiline" check box for typing multiple lines of text.

Add the following in "stdafx.h" to import the Voice Engine Component

//
...
#include 	// MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#import "C:\WINNT\Speech\vtxtauto.tlb" no_namespace
 /{{AFX_INSERT_LOCATION}}
...
//

Compile "stdafx.cpp" file, which results in creation of two new files (1) vtxtauto.tlh, (2) vtxtauto.tli in the Debug/Release folder . These files give interface IVTxtAuto wrapper method implementations. Browse through SPEAKFLAGS structure present in vtxtauto.tlh and the other methods.

Now is the time to call the engine through the IVTxtAuto Interface. Add these variables in "SpeakTextDlg.h"

//
char sText[1000];	//a char array of required length
CLSID clsid;		//class id 
HRESULT hr;		//for holding results
IVTxtAuto *voicePtr; 	//a pointer to IVTxtAuto inteface
//

Add the following piece of code in OnInitDialog() function

//
CSpeakTextDlg::OnInitDialog()
{
	...
	// Initializing COM
	hr = CoInitialize(NULL);
	//Getting the CLSID from Program name
	hr = CLSIDFromProgID(OLESTR("Speech.VoiceText.1"), &clsid);
	//Creating the instance of the Component
	hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IVTxtAuto),
	                      (LPVOID*)&voicePtr);

	if (FAILED(hr))
	{
	   AfxMessageBox("Cannot Initialize Speech Engine");
	   return FALSE;
	}
	else
	{
	   _bstr_t pszSite;
	   
	   //Reqister function should be called first prior calling Speak function
	   //so that the application is registered for using voice engine
	   voicePtr->Register(pszSite,"Radio");
	   voicePtr->Speak("Welcome to Text to Voice Convertion Engine",vtxtsp_NORMAL);
	   voicePtr->Speak("Type your Text and ask me to speak",vtxtsp_NORMAL);
	}
	...
}
//

Add the following onclick handler for the "Speak" button

//
CSpeakTextDlg::OnSpeak()
{
...
   GetDlgItemText(IDC_TEXT, sText, 200);

   if (0 == strcmp(sText,"\0") )
      voicePtr->Speak("What can i speak for you",vtxtsp_NORMAL);
   else
      voicePtr->Speak(sText,vtxtsp_NORMAL);
...
}
//

Change the second parameter of Speak Function according  to the value of the SPEAKFLAGS structure present in vtxtauto.tlh. Add the following code for respective buttons

//
void CSpeakTextDlg::OnPause() 
{
	voicePtr->AudioPause();
}

void CSpeakTextDlg::OnResume() 
{
	voicePtr->AudioResume();
}

CSpeakTextDlg::OnStop()
{
   voicePtr->StopSpeaking();
}
//

That's all. Build and Run the application.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Jagadish.G
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
Questioni need vtxtauto.tlb Pin
zylosx24-Oct-07 23:25
memberzylosx24-Oct-07 23:25 
AnswerRe: i need vtxtauto.tlb Pin
newmetic24-Sep-08 23:50
membernewmetic24-Sep-08 23:50 
Generalruntime error!!! Pin
ghostdeath16-Oct-07 8:51
memberghostdeath16-Oct-07 8:51 
i can compile ,but not execute this program

it warn

Runtime Error!
...............................
abnormal program termination

please tell me to debug it
Questionvtxtauto.tlb? Pin
baekjinug17-Dec-06 14:06
memberbaekjinug17-Dec-06 14:06 
Generalcannot initialize speech engine! Pin
Mihai Moga29-Mar-06 23:02
memberMihai Moga29-Mar-06 23:02 
QuestionHi,Can you help me? Pin
sinmorn24-May-04 14:37
membersinmorn24-May-04 14:37 
GeneralHelp Pin
sinmorn18-Apr-04 15:47
membersinmorn18-Apr-04 15:47 
Questionwhere is sphelper.h ? Pin
jbmyt30-Sep-03 8:10
memberjbmyt30-Sep-03 8:10 
QuestionWhy so complicate....??? Pin
Nikolai Teofilov28-Aug-03 1:36
memberNikolai Teofilov28-Aug-03 1:36 
Questioncan i get rid from the speech-sdk? Pin
FARTal_error4-Aug-03 10:19
memberFARTal_error4-Aug-03 10:19 
GeneralGreat work Pin
abhinaba28-Jul-03 19:38
memberabhinaba28-Jul-03 19:38 
QuestionSave as .wav? Pin
Gernot Frisch11-Apr-03 0:00
memberGernot Frisch11-Apr-03 0:00 
Generalfail to CLSIDFromProgID Pin
Eliran16-Feb-03 7:19
memberEliran16-Feb-03 7:19 
GeneralOther Language Pin
JLHJ11-Feb-03 9:59
memberJLHJ11-Feb-03 9:59 
GeneralSapi com object Pin
Wayne Scholar12-Nov-02 16:15
memberWayne Scholar12-Nov-02 16:15 
GeneralRe: Sapi com object Pin
Anonymous18-Feb-03 8:46
sussAnonymous18-Feb-03 8:46 
GeneralRe: Sapi com object Pin
Wayne Scholar18-Feb-03 8:46
sussWayne Scholar18-Feb-03 8:46 
Questionis it possible to change the voice ? Pin
lolont17-Sep-02 3:39
memberlolont17-Sep-02 3:39 
GeneralWorked fine once! Pin
WREY16-Sep-02 22:10
memberWREY16-Sep-02 22:10 
GeneralRe: Worked fine once! Pin
cdr17-Sep-02 5:24
membercdr17-Sep-02 5:24 
GeneralRe: Worked fine once! Pin
Anonymous17-Sep-02 6:54
sussAnonymous17-Sep-02 6:54 
GeneralRe: Worked fine once! Pin
WREY17-Sep-02 10:57
memberWREY17-Sep-02 10:57 
GeneralRe: Worked fine once! Pin
lolont18-Sep-02 5:26
memberlolont18-Sep-02 5:26 
QuestionOther langage ? Pin
Anonymous16-Sep-02 0:00
sussAnonymous16-Sep-02 0:00 
GeneralOther Systems Pin
Ed Gadziemski15-Sep-02 3:38
memberEd Gadziemski15-Sep-02 3:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150901.1 | Last Updated 14 Sep 2002
Article Copyright 2002 by Jagadish.G
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid