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

本文介绍如何在C++Builder中使用TTS(Text To Speech)功能,通过导入Vtxtauto.tlb类型库并创建相应的COM接口来实现语音合成。文章提供了详细的步骤说明及示例代码。
部署运行你感兴趣的模型镜像
在C++Builder使用TTS(Text To Speech) (转)[@more@]  启动BCB,打开菜单项PROJECT->Import Type Library...,在弹出的对话框中单击Add,选择 windowsspeech目录下的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:    // ide-managed Components
        TEdit *Edit1;
        TButton *Button1;
        void __fastcall FormCreate(T object *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 source "*.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 api 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. ASP method=post>

还可以利用Variant使用TTS 

 


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-989085/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-989085/

您可能感兴趣的与本文相关的镜像

HunyuanVideo-Foley

HunyuanVideo-Foley

语音合成

HunyuanVideo-Foley是由腾讯混元2025年8月28日宣布开源端到端视频音效生成模型,用户只需输入视频和文字,就能为视频匹配电影级音效

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值