静脉 发表于 2020-10-13 09:42:43

Unity 文字转换语音

**** 本内容需购买 ****


使用Interop.SpeechLib.dll,实现文字转语音操作,windows系统可用,其余系统还没试过
打包设置,在P Settings中,将Api Compatibility Level选择为.Net4.x,如图所示:否则打包会没有声音



//SpVoice voice = new SpVoice();//实例化
//voice.Voice = voice.GetVoices(string.Empty string.Empty).Item(0);//设置中文语音
//voice.Voice = voice.GetVoices(string.Empty string.Empty).Item(1);设置英文语音
//voice.Rate = 2;//语音速度,范围-10到10,默认是0
//voice.Volume = 100;//语音音量,范围0到100,默认是100
//voice.Pause();//暂停
//voice.Resume();//继续播放
//voice.Speak(text SpeechVoiceSpeakFlags.SVSFDefault); //同步朗读
//voice.Speak(text SpeechVoiceSpeakFlags.SVSFlagsAsync);//异步朗读

Weidaliya 发表于 2024-11-11 22:06:57

学到了~感谢楼主分享!
页: [1]
查看完整版本: Unity 文字转换语音