Start BCB, open the menu item Project->import Type Library ..., click Add in the Pop-up dialog box, select Vtxtauto.tlb under Windows\speech directory, and join Vtxtauto[version 1.0] One item. Clicking OK,BCB automatically generates a vtxtauto_tlb.cpp file. This file contains the COM class interface of the TTS engine, which can be used to communicate with DLL files. Create a new project to include this file in:
The source code is as follows:
//unit.h
#ifndef unit1h
#define UNIT1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class Tform1:public Tform
{
__published://Ide-managed Components
Tedit *edit1;
TButton *button1;
void __fastcall formcreate (TObject *sender);
void __fastcall Button1Click (TObject *sender);
Private://User declarations
public://User declarations
__fastcall TForm1 (tcomponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *form1;
//---------------------------------------------------------------------------
#endif
//unit.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "wstring.h"
#include "vtxtauto_tlb.h"
//---------------------------------------------------------------------------
#pragma package (smart_init)
#pragma resource "*.DFM"
TForm1 *form1;
Ivtxtauto *ivtxtauto1;
//---------------------------------------------------------------------------
__fastcall Tform1::tform1 (tcomponent* Owner)
: Tform (Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall tform1::formcreate (tobject *sender)
{
widestring a = "Demo1";
widestring B = "Project1.exe";
widestring c= "Hi,i am trying to speak to you,do me?";
IVTxtAuto1 = NULL;
CoInitialize (NULL);
Olecheck (CoCreateInstance (Clsid_vtxtauto_,0,clsctx_all,iid_ivtxtauto, (lpvoid*) &IVTxtAuto1));
Ivtxtauto1->register (A,B);
ivtxtauto1->set_enabled (1);
Ivtxtauto1->set_speed (150);
Ivtxtauto1->speak (C,vtxtsp_veryhigh);
}
//---------------------------------------------------------------------------
void __fastcall Tform1::button1click (tobject *sender)
{
if (IVTxtAuto1!= NULL)
{
Ivtxtauto1->speak ((widestring) edit1->text,vtxtsp_veryhigh);
showmessage ("OK");//My debug statement (no sound card)
}else{
showmessage ("Server did not initialize successfully");
}
}
//---------------------------------------------------------------------------
//project.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
useres ("Project1.res");
useform ("Unit1.cpp", Form1);
useunit ("D:\Borland\CBuilder5\Imports\VTxtAuto_TLB"). CPP ");
//---------------------------------------------------------------------------
WINAPI WinMain (hinstance, HINSTANCE, LPSTR, int)
{
Try
{
application->initialize ();
Application->createform (__classid (TFORM1), &form1);
Application->run ();
}
catch (Exception &exception)
{
application->showexception (&exception);
}
return 0;
}
//---------------------------------------------------------------------------
You can also use a variant with TTS