在C++Builder使用TTS(Text To Speech) (轉)
在C++Builder使用TTS(Text To Speech) (轉)[@more@] 啟動BCB,開啟選單項PROJECT->Import Type Library...,在彈出的對話方塊中單擊Add,選擇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
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // -managed Components
TEdit *Edit1;
TButton *Button1;
void __fastcall FormCreate(T *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 re "*.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:BorlandCBuilder5ImportsVTxtAuto_TLB.CPP");
//---------------------------------------------------------------------------
WIN WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
//---------------------------------------------------------------------------RM onsubmit="return input(this)" action=/expert/replynews. method=post>
原始碼如下:
//Unit.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // -managed Components
TEdit *Edit1;
TButton *Button1;
void __fastcall FormCreate(T *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 re "*.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:BorlandCBuilder5ImportsVTxtAuto_TLB.CPP");
//---------------------------------------------------------------------------
WIN 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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-989085/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 口播神器,基於Edge,微軟TTS(text-to-speech)文字轉語音免費開源庫edge-tts實踐(Python3.10)微軟TTSPython
- 怎樣在C++Builder中建立使用DLL (轉)UI
- PR語音轉字幕轉換外掛Speech to Text for Premiere Pro 2022REM
- 在C++Builder 5中使用ADO資料庫程式設計 (轉)C++UI資料庫程式設計
- 在C++Builder中建立共享記憶體段 (轉)C++UI記憶體
- C++Builder使用ADSI建立web站點 (轉)C++UIWeb
- 在C++Builder中建立Access odbc資料來源 (轉)C++UI
- 用C++Builder在WINNT下編制一個Service (轉)C++UI
- TTS的總結 (轉)TTS
- Hello World by Microsoft Speech SDK 5.1 (轉)ROS
- 在Excel中如何使用TEXT函式?Excel函式
- c++builder快捷鍵大全 (轉)C++UI
- C++BUILDER 6 新特色 (轉)C++UI
- Mac字轉語音工具Speech for MacMac
- ORACLE TEXT(轉)Oracle
- 用 C++Builder 編寫 Tray 程式 (轉)C++UI
- Borland C++Builder .RES 中文化 (轉)C++UI
- C++Builder常用程式碼片斷 (轉)C++UI
- C++Builder的編譯超頻 (轉)C++UI編譯
- C# TTS-文字轉語音C#TTS
- C++Builder的幾則小應用 (轉)UI
- 用C++Builder建立數字簽名 (轉)C++UI
- C++Builder下實現埠讀寫 (轉)C++UI
- C++BUILDER中幾種容器的使用C++UI
- 使用C++Builder建立自定義VCL元件時的一些問題 (轉)C++UI元件
- 利用C++Builder進行精確計時 (轉)C++UI
- CSS:text-transform(轉)CSSORM
- 科大訊飛離線lunix tts demo使用TTS
- 使用者操作語音提示,Web Speech API 的簡單使用WebAPI
- 用C++Builder實現Word 97自動化 (轉)UI
- C++Builder和Delphi中的復活節彩蛋 (轉)C++UI
- Visual C++與Delphi/C++Builder之比較 (轉)C++UI
- 用C++Builder 5開發Windows下的屏保 (轉)C++UIWindows
- TTS技術TTS
- TTS朗讀中文(using sapi sdk5) (轉)TTSAPI
- CSS文字:text-justify(轉)CSS
- CSS文字:text-autospace(轉)CSS
- CSS文字:text-overflow(轉)CSS