使用RTVoice预制体就可以了,可以转汉字和英文,标点符号不行。
自己写的测试代码:文章来源地址https://www.toymoban.com/news/detail-734556.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Crosstales.RTVoice;
public class VoiceDemo : MonoBehaviour
{
public InputField mTxtSpeakContent;
public Button mBtnClick;
private string mID;
// Start is called before the first frame update
void Start()
{
mBtnClick.onClick.AddListener(() => {
//Speak(mTxtSpeakContent.text);
mID = Speaker.Instance.Speak(mTxtSpeakContent.text);
});
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
mID = Speaker.Instance.Speak("测试语音功能是否正常!Test whether the voice function is normal",null, Speaker.Instance.Voices[0]);
//Speaker.Instance.SpeakNative("测试语音功能是否正常!Test whether the voice function is normal", Speaker.Instance.Voices[0], 1, 1, 1);
Debug.Log("开始ID:" + mID);
Speaker.Instance.OnSpeakStart += SpeakStart;
Speaker.Instance.OnSpeakComplete += SpeakComplete;
//Speaker.Instance.Speak("why");//测试语音功能是否正常!
}
if (Input.GetKeyDown(KeyCode.O))
{
Speaker.Instance.Silence(mID);
mID = Speaker.Instance.Speak("我的目的是来测试id的", null, Speaker.Instance.Voices[0]);
Debug.Log("开始ID:" + mID);
Speaker.Instance.OnSpeakComplete += SpeakComplete;
}
if (Input.GetKeyDown(KeyCode.M))
{
Speaker.Instance.PauseOrUnPause();
}
if (Input.GetKeyDown(KeyCode.N))
{
Speaker.Instance.PauseOrUnPause();//
}
if (Input.GetKeyDown(KeyCode.Y))
{
Speaker.Instance.Silence(mID);//静默(介绍播放)
}
}
private void SpeakStart(Crosstales.RTVoice.Model.Wrapper wrapper)
{
Debug.Log("开始播放ID:" + wrapper.Uid);
}
private void SpeakComplete(Crosstales.RTVoice.Model.Wrapper wrapper)
{
Debug.Log("完成ID:" + wrapper.Uid);
if (wrapper.Uid.Equals(mID))
{
}
}
public void Speak(string _conetnt)
{
mID = Speaker.Instance.Speak(_conetnt, null, Speaker.Instance.Voices[0]);
}
}
文章来源:https://www.toymoban.com/news/detail-734556.html
到了这里,关于Unity文字转语音(使用RT-Voice)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!