C++BUILDER 下開發語音源碼,轉載

 XP上可以安裝Speech SDK5.11.將sapi.dll導入到C++Builder:Component->Import Component->Import a Type Library->Add添加Sapi.dll語音識別引擎庫文件。2.Install完後會生成許多語音控件,添加spVoice控件3.可以進行編程了:#include #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;iget_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));}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章