全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1334
推到 Plurk!
推到 Facebook!

在C++Builder使用TTS(Text To Speech)

 
jackkcg
站務副站長


發表:891
回覆:1050
積分:848
註冊:2002-03-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-09-30 01:54:30 IP:61.70.xxx.xxx 未訂閱
在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
------
**********************************************************
哈哈&兵燹
最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好

Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知
K.表Knowlege 知識,就是本站的標語:Open our mind
markov
中階會員


發表:55
回覆:135
積分:53
註冊:2003-12-01

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-03-07 13:43:46 IP:61.229.xxx.xxx 未訂閱
我是用windows xp 為何我找不到Vtxtauto.tlb 應該要安裝什麼才會有嗎?
huangcks
一般會員


發表:1
回覆:2
積分:0
註冊:2004-04-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-21 16:34:44 IP:218.160.xxx.xxx 未訂閱
我照做了,run出現 "伺服器沒有初始化成功" 為什麼,有人可以回答我嗎??
系統時間:2024-06-26 9:23:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!