usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingSpeechLib;publicclassTTS_YuYin:MonoBehaviour{SpVoice voice;// Start is called before the first frame updatevoidStart(){//实例化spvoice 对象
voice =newSpVoice();//Item(0)中文语音 Item(1)英文语音
voice.Voice = voice.GetVoices(string.Empty,string.Empty).Item(0);//语音速度 范围-10 到10 默认是0
voice.Rate =0;//语音音量 范围0到100 默认 100
voice.Volume =100;}// Update is called once per framevoidUpdate(){if(Input.GetKeyDown(KeyCode.Q)){//同步朗读(同步朗读时系统会卡在这里,关都关不掉 直到朗读完毕才会往下执行,建议使用异步朗读)//voice.Speak("hello world 是大师级的卡拉胶SD卡圣诞节啊斯柯达SDKask大开杀戒的卡建档立卡");//异步朗读
voice.Speak(
"金樽清酒斗十千,玉盘珍羞直万钱。
停杯投箸不能食,拔剑四顾心茫然。
欲渡黄河冰塞川,将登太行雪满山。(雪满山 一作:雪暗天)
闲来垂钓碧溪上,忽复乘舟梦日边。(碧 一作:坐)
行路难,行路难,多歧路,今安在?
长风破浪会有时,直挂云帆济沧海。",
SpeechVoiceSpeakFlags.SVSFlagsAsync);}if(Input.GetKeyDown(KeyCode.W)){//暂停使用该对象的所有朗读进程,同步朗读下无法使用该方法暂停
voice.Pause();}if(Input.GetKeyDown(KeyCode.E)){//恢复该对象所对应的被暂停的朗读进程
voice.Resume();}}privatevoidOnApplicationQuit(){
voice.Pause();}}