微软的SAPI提供强大的Text To Speech接口且支持自动化。可在.Net程序中引入该COM组件,通过添加引用、调用相关类的方法实现简单句子发言,还能用SpFileStream创建音频流将文本“读”到wav文件中。不过英文版win2003自带SAPI不支持中文,5.1版本可支持中日英,可到MS网站免费下载。
//Declare the SpVoice object. ISpeechVoice v=new SpVoiceClass(); //Create a wave stream SpFileStream s =new SpFileStream(); //Create a new .wav file for writing. s.Open("out.wav", SpeechStreamFileMode.SSFMCreateForWrite, false); //Set the .wav file stream as the output for the Voice object v.AudioOutputStream = s; //Call the Speak method now will send the output to the .wav file. v.Speak(txtSpeak, SpeechVoiceSpeakFlags.SVSFDefault); //Close the file s.Close();