flyup
資深會員
發表:280 回覆:508 積分:385 註冊:2002-04-15
發送簡訊給我
|
在C++Builder使用TTS(Text To Speech)
啟動BCB,打開選單項PROJECT->Import Type Library...,在彈出的對話框中單擊Add,選擇windows\speech目錄下的Vtxtauto.tlb,加入VtxtAuto[Version 1.0]一項。單擊OK,BCB就會自動生成一個VtxtAuto_TLB.cpp文件。這個文件包含了TTS引擎的COM類介面,可以用來與DLL文件通信。新建一個工程,將這個文件包含進來.
源碼如下:
//Unit.h #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#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
#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 you hear 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");//我的調試語句(沒聲卡)
}else{
ShowMessage("服務器沒有初始化成功");
}
}
//---------------------------------------------------------------------------
//Project.cpp
//--------------------------------------------------------------------------- #include
#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;
}
//--------------------------------------------------------------------------- 還可以利用Variant使用TTS
|
browningchi
一般會員
發表:4 回覆:3 積分:1 註冊:2002-11-28
發送簡訊給我
|
請問一下 這個是什麼功能
小弟不太董 引言:
在C Builder使用TTS(Text To Speech)
啟動BCB,打開選單項PROJECT->Import Type Library...,在彈出的對話框中單擊Add,選擇windows\speech目錄下的Vtxtauto.tlb,加入VtxtAuto[Version 1.0]一項。單擊OK,BCB就會自動生成一個VtxtAuto_TLB.cpp文件。這個文件包含了TTS引擎的COM類介面,可以用來與DLL文件通信。新建一個工程,將這個文件包含進來.
源碼如下:
//Unit.h #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#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
#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 you hear 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");//我的調試語句(沒聲卡)
}else{
ShowMessage("服務器沒有初始化成功");
}
}
//---------------------------------------------------------------------------
//Project.cpp
//--------------------------------------------------------------------------- #include
#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;
}
//--------------------------------------------------------------------------- 還可以利用Variant使用TTS
|
jenwe
一般會員
發表:34 回覆:38 積分:24 註冊:2007-03-23
發送簡訊給我
|
所謂TTS~就是將英文字轉語音檔~無論是什麼單字都可以~這個程式是利用動態資料庫連結的方式去呼叫!!
===================引 用 browningchi 文 章===================
請問一下 這個是什麼功能 小弟不太董
|