欢迎来到天天文库
浏览记录
ID:1237943
大小:80.45 KB
页数:7页
时间:2017-11-09
《在c#中的语音合成与识别技术》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、在.net中,对英文语音有较好的支持,但是对中文语音的支持还没有加入进来,我们要想实现中文发音或中文语音识别,必需先安装微软的SpeechApplicationSDK(SASDK),它的最新版本是SAPI5.1他能够识别中、日、英三种语言,你可以在这里下载:http://www.microsoft.com/speech/download/sdk51/,需要安装这两个文件SpeechSDK5.1和5.1LanguagePack,其中5.1LanguagePack可以选择安装支持的语言。 安装好以后,我们就可以开始进行语音程序的开发了,当然,在这之前我们需要把SAPI.dll
2、通过如下图所示添加到引用中 下面我们设计一个能够朗读中英文混合语言的类: 我们将用单例模式实现该类,类的代码如下,我们将详细解释:publicclassSpeach{ privatestaticSpeach_Instance=null; privateSpeechLib.SpVoiceClassvoice=null; privateSpeach() { BuildSpeach(); }publicstaticSpeachinstance(){ if(_Instance==null) _Instance=newSpeach(); return_Instance;}p
3、rivatevoidSetChinaVoice(){ voice.Voice=voice.GetVoices(string.Empty,string.Empty).Item(0);}privatevoidSetEnglishVoice(){ voice.Voice=voice.GetVoices(string.Empty,string.Empty).Item(1);}privatevoidSpeakChina(stringstrSpeak){ SetChinaVoice(); Speak(strSpeak);}privatevoidSpeakEnglishi(strings
4、trSpeak){ SetEnglishVoice(); Speak(strSpeak);}publicvoidAnalyseSpeak(stringstrSpeak){ intiCbeg=0; intiEbeg=0; boolIsChina=true; for(inti=0;i=65) { intiLen=i-iCbeg; stringstrValue=strSpeak.Substring(iCb
5、eg,iLen); SpeakChina(strValue); iEbeg=i; IsChina=false; } } else { if(chr>122
6、
7、chr<65) { intiLen=i-iEbeg; stringstrValue=strSpeak.Substring(iEbeg,iLen); this.SpeakEnglishi(strValue); iCbeg=i; IsChina=true; } } }//endfor if(IsChina) { intiLen=strSpeak.Le
8、ngth-iCbeg; stringstrValue=strSpeak.Substring(iCbeg,iLen); SpeakChina(strValue); } else { intiLen=strSpeak.Length-iEbeg; stringstrValue=strSpeak.Substring(iEbeg,iLen); SpeakEnglishi(strValue); }}privatevoidBuildSpeach(){ if(voice==null) voice=newSpVoiceClass();}publicintVolume{ get {
9、 returnvoice.Volume; } set { voice.SetVolume((ushort)(value)); }}publicintRate{ get { returnvoice.Rate; } set { voice.SetRate(value); }}privatevoidSpeak(stringstrSpeack){ try { voice.Speak(strSpeack,SpeechVoiceSpeakFlags.SVSFlagsAsync); } catch(Exceptione
此文档下载收益归作者所有