C++BUILDER 下开发语音源码,转载

来源:互联网 发布:证券公司 网络金融 编辑:程序博客网 时间:2024/05/18 15:51
 XP上可以安装Speech SDK5.11.将sapi.dll导入到C++Builder:Component->Import Component->Import a Type Library->Add添加Sapi.dll语音识别引擎库文件。2.Install完后会生成许多语音控件,添加spVoice控件3.可以进行编程了:#include <vcl.h>#pragma hdrstop#include "Unit1.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma link "ACTIVEVOICEPROJECTLib_OCX"#pragma link "SpeechLib_OCX"#pragma resource "*.dfm"TForm1 *Form1;TSpVoice *SpVoice1;//=new TSpVoice(this);ISpeechObjectTokensPtr sots;//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){}//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender){WideString con=Memo1->Text; //中文=804;英文=409sots=SpVoice1->GetVoices(WideString("Language=409"),WideString("VW Kate"));//获取中文语音(wchar_t*)("")if(sots->get_Count()==0)//如果没有中文语音,则count为0return;SpVoice1->_set_Voice(sots->Item(0));//设置中文发音SpVoice1->Speak(con,SVSFDefault);//快乐的说吧}//---------------------------------------------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender){SpVoice1=new TSpVoice(this);ComboBox1->Items->Clear();ComboBox1->Items->Add("声音");sots=SpVoice1->GetVoices(NULL,NULL);for(int i=0;i<sots->get_Count();i++){ComboBox1->Items->Add(sots->Item(i)->GetDescription(NULL));}}//---------------------------------------------------------------------------void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action){delete SpVoice1;}//---------------------------------------------------------------------------void __fastcall TForm1::ComboBox1Change(TObject *Sender){SpVoice1->_set_Voice(sots->Item(ComboBox1->ItemIndex));}
原创粉丝点击