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

铁路运输安全保护条例
C++Builder使用TTS(Text To Speech)
稀土永磁启动BCB,打开菜单项PROJECT->Import ,cdn服务在弹出的对话框中单击Add,选择windows\speech目录下的Vtxtauto.tlb,加入VtxtAuto[Version 1.0]一项。单击OKBCB就会自动生成一个VtxtAuto_TLB.cpp文件。这个文件包含TTS引擎的COM类接口,可以用来与DLL文件通信。新建一个工程,将这个文件包含进来:
源码如下:
//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 = "";
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 <vcl.h>
#pragma hdrstop
USERES("s");
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

本文发布于:2024-09-21 03:35:05,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/371127.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:刷题吧-答案
标签:文件   包含   服务   电子科技
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议