Using TTS (Text to Speech) in C + + Builder

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.