Click here to Skip to main content
Click here to Skip to main content

Using Text to Voice Interfaces

By , 13 Sep 2002
 

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

About the Author

Jagadish.G
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questioni need vtxtauto.tlbmemberzylosx24 Oct '07 - 23:25 
AnswerRe: i need vtxtauto.tlbmembernewmetic24 Sep '08 - 23:50 
Generalruntime error!!!memberghostdeath16 Oct '07 - 8:51 
Questionvtxtauto.tlb?memberbaekjinug17 Dec '06 - 14:06 
Generalcannot initialize speech engine!memberMihai Moga29 Mar '06 - 23:02 
QuestionHi,Can you help me?membersinmorn24 May '04 - 14:37 
GeneralHelpmembersinmorn18 Apr '04 - 15:47 
Questionwhere is sphelper.h ?memberjbmyt30 Sep '03 - 8:10 
QuestionWhy so complicate....???memberNikolai Teofilov28 Aug '03 - 1:36 
Questioncan i get rid from the speech-sdk?memberFARTal_error4 Aug '03 - 10:19 
it is required to have the speech-sdk installed for executing a programm using speech...
but is there no possibility to get rid from the sdk and run my application on systems which dont have the sdk installed?
Unsure | :~ Confused | :confused:
GeneralGreat workmemberabhinaba28 Jul '03 - 19:38 
QuestionSave as .wav?memberGernot Frisch11 Apr '03 - 0:00 
Generalfail to CLSIDFromProgIDmemberEliran16 Feb '03 - 7:19 
GeneralOther LanguagememberJLHJ11 Feb '03 - 9:59 
GeneralSapi com objectmemberWayne Scholar12 Nov '02 - 16:15 
GeneralRe: Sapi com objectsussAnonymous18 Feb '03 - 8:46 
GeneralRe: Sapi com objectsussWayne Scholar18 Feb '03 - 8:46 
Questionis it possible to change the voice ?memberlolont17 Sep '02 - 3:39 
GeneralWorked fine once!memberWREY16 Sep '02 - 22:10 
GeneralRe: Worked fine once!membercdr17 Sep '02 - 5:24 
GeneralRe: Worked fine once!sussAnonymous17 Sep '02 - 6:54 
GeneralRe: Worked fine once!memberWREY17 Sep '02 - 10:57 
GeneralRe: Worked fine once!memberlolont18 Sep '02 - 5:26 
QuestionOther langage ?sussAnonymous16 Sep '02 - 0:00 
GeneralOther SystemsmemberEd Gadziemski15 Sep '02 - 3:38 
GeneralRe: Other Systemsmemberhaivh15 Sep '02 - 18:11 

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

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