在C++Builder使用Microsoft Speech SDK 5.1进行中文朗读的.
在VC下使用Microsoft Speech SDK 5.1进行中文朗读的,用得很熟悉,可是这次是在C++Builder中使用,以前写的函数都没有用了!
我要实现的是在在C++Builder下用Microsoft Speech SDK 5.1进行中文朗读的到一个WAV文件中.急啊!帮忙!
[解决办法]
调用:
Pronounce(SpVoice1,WordStructTemp.Word,false);
函数
void TFMain::Pronounce(TSpVoice *tsv, string SoundText,bool IsEnglish)
{
try
{
if(IsEnglish)
{
tsv-> Voice=Voices( "english "); //英文发音 //要修改
tsv-> Rate= 0;//速度-10 到 10
}
else
{
tsv-> Voice=Voices( "chinese_m "); //中文发音
tsv-> Rate= -10;//速度-10 到 10
}
if(SoundText == " ")
{
tsv-> Volume = 0;
SoundText = "about ";
}
else
{
tsv-> Volume = 50; //音量 0 到 100
}
replace(SoundText.begin(),SoundText.end(), '. ', ' ');
tsv-> Speak(SoundText.c_str() ,1);
}
catch(...)
{
//ShowDialogForm( "DNoRecord ", "语音库不存在,请安装语音库 ",true);
if(JustCount == 0)
{
TFXDialog *dl = new TFXDialog(Application);
dl-> Left = Left + 252;
dl-> Top = Top + 219;
dl-> Notebook1-> ActivePage = "PShow ";
//dl-> Label24-> Caption = "同一词组,是否重新初始化? ";
dl-> Label24-> Caption = "语音库不存在,\n是否安装语音库? ";
if(dl-> ShowModal() == 1)
{
String filename = ExtractFileDir(Application-> ExeName) + "\\ "; //要改
ShellExecute(Handle, "Open ", "SoundSetup.exe ", " ",filename.c_str(),SW_SHOWNORMAL);
}
delete dl;
JustCount = 1;
}
if(tsv-> Name == "SpVoice2 ")
Timer4-> Enabled = true;
//BrowseNum();
}
}
//---------------------------------------
[解决办法]
//---------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
pVoice = NULL;
if ( SUCCEEDED(::CoInitialize(NULL)) )
if (::CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL,
IID_ISpVoice, (void **)&pVoice) != S_OK)
pVoice = NULL;
}
//---------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
if ( pVoice )
{
pVoice->Release();
pVoice = NULL;
}
::CoUninitialize();
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Button1->Enabled = false;
if ( pVoice )
{
WideString wsText = WideString(Memo1->Lines->Text);
pVoice->Speak(wsText.c_bstr(), 0, NULL);
}
Button1->Enabled = true;
}
//---------------------------------------
void __fastcall TForm1::TrackRateChange(TObject *Sender)
{
if ( pVoice )
{
RateValue->Caption = TrackRate->Position;
pVoice->SetRate(TrackRate->Position - 10);
}
}
//---------------------------------------
void __fastcall TForm1::TrackVolumeChange(TObject *Sender)
{
if ( pVoice )
{
VolumeValue->Caption = TrackVolume->Position;
pVoice->SetVolume(TrackVolume->Position * 5);
}
}
//--------------------------------
[解决办法]
这是本科的时候写的
你参考一下
希望能榜上你
/*
After setup Speech sdk5.1,in C++builder
select Project->Import Type Library
then select Micosoft Speech Object Library[Version5.1] ActiveX companent
import it
then in .h file
add
*/
//.h
IVTxtAuto *ivta_Speech;
/////////////////////////////////
//.cpp
void __fastcall Tfrm_Main::SpeakString(String s_Str)
{
WideString ws_CreateSound = (WideString)s_Str;
//OLECHAR bstr[MAX_PATH*2];
WideString r_a = "Demo";
WideString r_b = "p_MasterSystem.exe";
//Application->Name.WideChar(bstr,Application->Name.WideCharBufSize());
ivta_Speech = NULL;
CoInitialize(NULL);
OleCheck(CoCreateInstance(CLSID_VTxtAuto_,0,CLSCTX_ALL,IID_IVTxtAuto,(LPVOID*)&ivta_Speech));
ivta_Speech->Register(r_a,r_b);
ivta_Speech->set_Enabled(1);
ivta_Speech->set_Speed(150);
ivta_Speech->Speak(ws_CreateSound,vtxtst_STATEMENT+vtxtst_READING) ;
}
//Add a function SpeakString
//then you can use
SpeakString(”I Can Speak now!”);