using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SpeechLib;
public class TTS_YuYin : MonoBehaviour
{
SpVoice voice;
void Start()
{
voice = new SpVoice();
voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
voice.Rate = 0;
voice.Volume = 100;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
voice.Speak(
"金樽清酒斗十千,玉盘珍羞直万钱。
停杯投箸不能食,拔剑四顾心茫然。
欲渡黄河冰塞川,将登太行雪满山。(雪满山 一作:雪暗天)
闲来垂钓碧溪上,忽复乘舟梦日边。(碧 一作:坐)
行路难,行路难,多歧路,今安在?
长风破浪会有时,直挂云帆济沧海。",
SpeechVoiceSpeakFlags.SVSFlagsAsync);
}
if (Input.GetKeyDown(KeyCode.W))
{
voice.Pause();
}
if (Input.GetKeyDown(KeyCode.E))
{
voice.Resume();
}
}
private void OnApplicationQuit()
{
voice.Pause();
}
}
下载地址:http://dl.dllzj.com:81/I/Interop.SpeechLib.zip
原文地址:https://www.cnblogs.com/qq2351194611/p/14446646.html