ITPub博客

首页 > 应用开发 > IT综合 > 在C++Builder使用TTS(Text To Speech) (转)

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

原创 IT综合 作者:amyz 时间:2007-11-29 17:09:18 0 删除 编辑
在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(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:BorlandCBuilder5ImportsVTxtAuto_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;
}
//--------------------------------------------------------------------------- RM onsubmit="return input(this)" action=/expert/replynews.ASP method=post>

还可以利用Variant使用TTS 

 


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

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7282287