Creating a Text-to-Voice Convention


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Environment: VC6, Win2k

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

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
IVTxtAuto *voicePtr;       //a pointer to IVTxtAuto interface

Add the following piece of code in the OnInitDialog() function.

// 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,

if (FAILED(hr))
   AfxMessageBox("Cannot Initialize Speech Engine");
   return FALSE;
   _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->Speak("Welcome to Text to Voice Conversion Engine",
   voicePtr->Speak("Type your Text and ask me to speak",

Add the following on the click of the Speak button:

   GetDlgItemText(IDC_TEXT, sText, 200);

   if (0 == strcmp(sText,"\0") )
      voicePtr->Speak("What can I speak for you",vtxtsp_NORMAL);

Add the following code on the click of the Stop button


That's all. Build and run the application. Wherever there is a need to give spoken information, call the speak function through the dialog.


Download demo project - 6 Kb


  • Linker Error On Release Configuartion

    Posted by Legacy on 03/27/2003 08:00am

    Originally posted by: John


    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:

    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
    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

  • Nice!

    Posted by Legacy on 01/26/2003 08:00am

    Originally posted by: R.V.Anand

    Hi Jaggu,

    Where do i get the speech engine components?.

  • AcitveVoice Control

    Posted by Legacy on 01/16/2003 08:00am

    Originally 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.

  • pretty

    Posted by Legacy on 10/04/2002 07:00am

    Originally posted by: idiot


  • More Voices

    Posted by Legacy on 09/17/2002 07:00am

    Originally posted by: sujeet

    I am using Microsoft Speech SDK 5.1 in my project. Its working fine n smooth. Only problem i am facing is restriction of voice as I can use only three default voices provided by Microsoft (Mike, Sam and Marry). Is there any way to incorporate more voices? 

  • small is beautiful.

    Posted by Legacy on 09/17/2002 07:00am

    Originally posted by: Small is beautiful. But how to do this in Visual C ?

    Respected Sir,
    The 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.

  • it's seem very good!

    Posted by Legacy on 09/16/2002 07:00am

    Originally posted by: leo fewldge

    here is the example too.

  • Woman voice

    Posted by Legacy on 09/14/2002 07:00am

    Originally posted by: Yaron

    Thanks! this is so cool!
    Does 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 07:00am

    Originally 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?

  • Well done ! But is it possible in Frensh ?

    Posted by Legacy on 09/13/2002 07:00am

    Originally 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" ?


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date