Creating a Text-to-Voice Convention
Prerequisites: On any Windows 2000-installed machine, check for a "Speech" folder under C:\WINNT. This folder contains all the necessary components to call the speech engine.
This article guides you through the steps necessary to create a simple COM client using MFC with the available type library file (.tlb). At the end, you will know how to create clients for any component when a type library file (.tlb) is available.
So, let's start creating a dialog-based MFC client application by firing the VC IDE.
Select File->New, select MFC AppWizard[exe], and Enter "SpeakText" as the Project name. Save it in the required location. Select the "Dialog Base" option and uncheck "Document/View Arch."
Use the resource editor to design a user interface dialog, as shown in the following figure.

Name your dialog and its controls accordingly.
Note: On the Styles tab of the edit control properties sheet, select the "Multiline" check box for typing multiple lines of text.
Add the following in "stdafx.h" to import the Voice Engine Component:
... #include <afxcmn.h> // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT #import "C:\WINNT\Speech\vtxtauto.tlb" no_namespace //{{AFX_INSERT_LOCATION}} ...
Compile the "stdafx.cpp" file and its results to create two new files, vtxtauto.tlh and vtxtauto.tli, in the Debug/Release folder. These files give the interface the IVTxtAuto wrapper method implementations.
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 or holding results HRESULT hr; IVTxtAuto *voicePtr; //a pointer to IVTxtAuto interface
Add the following piece of code in the OnInitDialog() function.
CSpeakTextDlg::OnInitDialog()
{
...
// Initializing COM
hr = CoInitialize(NULL);
//Getting the CLSID from the 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;
//The Register function should be called first prior to
//calling the Speak function so that the application is
//registered for using the voice engine.
voicePtr->Register(pszSite,"Radio");
voicePtr->Speak("Welcome to Text to Voice Conversion Engine",
vtxtsp_NORMAL);
voicePtr->Speak("Type your Text and ask me to speak",
vtxtsp_NORMAL);
}
...
}
Add the following on the click of 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);
...
}
Add the following code on the click of the Stop button
CSpeakTextDlg::OnStop()
{
voicePtr->StopSpeaking();
}
That's all. Build and run the application. Wherever there is a need to give spoken information, call the speak function through the dialog.

Comments
Linker Error On Release Configuartion
Posted by Legacy on 03/27/2003 12:00amOriginally posted by: John
Hallo
I tried to reproduce this sample and it worked out real fine! But when I tried to set the active Configuration to ... Win32 Release I got the following Error:
Linking...
LINK : warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
LINK : warning LNK4089: all references to "comdlg32.dll" discarded by /OPT:REF
LINK : error : Internal error during ReadSymbolTable
ExceptionCode = C0000005
ExceptionFlags = 00000000
ExceptionAddress = 00433A5D
NumberParameters = 00000002
ExceptionInformation[ 0] = 00000001
ExceptionInformation[ 1] = 00000002
CONTEXT:
Eax = 00000002 Esp = 0012F6D0
Ebx = 010A0701 Ebp = 002FD670
Ecx = 008364BE Esi = 01090940
Edx = 00000000 Edi = 01090E00
Eip = 00433A5D EFlags = 00010216
SegCs = 0000001B SegDs = 00000023
SegSs = 00000023 SegEs = 00000023
SegFs = 00000038 SegGs = 00000000
Dr0 = 0012F6D0 Dr3 = 010A0701
Dr1 = 002FD670 Dr6 = 008364BE
Dr2 = 00000000 Dr7 = 00000000
Error executing link.exe.
Tool execution canceled by user.
Please advise
ReplyNice!
Posted by Legacy on 01/26/2003 12:00amOriginally posted by: R.V.Anand
Hi Jaggu,
Where do i get the speech engine components?.
ReplyAcitveVoice Control
Posted by Legacy on 01/16/2003 12:00amOriginally posted by: C. T. Simonetti
Why doesn't the .Speak member function get exposed to your VC application when using the "insert ActiveX control" facility - from with a dialog? I am using MS VC++ .net and am in a MFC/Dialog application.
Replypretty
Posted by Legacy on 10/04/2002 12:00amOriginally posted by: idiot
pretty!!!!!!!!!
Replysmall is beautiful.
Posted by Legacy on 09/17/2002 12:00amOriginally posted by: Small is beautiful. But how to do this in Visual C ?
Respected Sir,
ReplyThe article gave me a vary good start. But I already have written an Telephony appliaction in C so there I think would problem of com objects can you guide me.
Thanks
Santosh
More Voices
Posted by Legacy on 09/17/2002 12:00amOriginally posted by: sujeet
Replyit's seem very good!
Posted by Legacy on 09/16/2002 12:00amOriginally posted by: leo fewldge
here is the example too.
Replyufirst.yeah.net
Woman voice
Posted by Legacy on 09/14/2002 12:00amOriginally posted by: Yaron
Thanks! this is so cool!
ReplyDoes anyone know if it has got the option to talk in a woman voice?
How to play through different devices
Posted by Legacy on 09/14/2002 12:00amOriginally posted by: Mike
The code sample was great! It worked right off the bat. One additional thing I wanted to know how to select the device I want to play through: different sound cards, modem etc.
Any suggestions?
ReplyWell done ! But is it possible in Frensh ?
Posted by Legacy on 09/13/2002 12:00amOriginally posted by: March'
It is a cool feature ! And it looks simple to create but I'm from France... So is it possible to make my computer speaking "en fran�ais" ?
March'
ReplyLoading, Please Wait ...