RTVoice 是 Unity 中一款轻量级的文字转语音(TTS)插件,支持跨平台运行(Windows、macOS、Android、iOS 等),无需依赖第三方服务即可实现本地语音合成。其核心功能包括动态生成语音、调节音调/语速/音量,并支持多语言。
RTVoice 文件夹位于 Assets 目录下。
Tools > RTVoice 打开设置面板,检查默认语音引擎是否可用(如 Windows 需安装 SAPI5 或 MS Speech Platform)。
调用 RTVoice.Instance.Speak() 方法生成语音,需指定文本、语音名称(可选)、音调、语速和音量:
using RTVoice;
// 简单示例
void SpeakText() {
RTVoice.Instance.Speak("Hello, this is a test.", null, 1.0f, 1.0f, 1.0f);
}null 使用系统默认语音,或通过 RTVoice.Instance.GetVoices() 获取可用语音列表。可绑定回调函数处理语音开始、结束等事件:
void Start() {
RTVoice.Instance.OnSpeakStart += (text) => Debug.Log("Speech started: " + text);
RTVoice.Instance.OnSpeakComplete += (text) => Debug.Log("Speech completed: " + text);
}通过 RTVoice.Instance.GetVoices() 获取当前系统支持的语音列表,筛选特定语言的语音:
void ListVoices() {
var voices = RTVoice.Instance.GetVoices();
foreach (var voice in voices) {
if (voice.Language == "en-US") {
Debug.Log("Available English Voice: " + voice.Name);
}
}
}Microphone 权限,并在构建时添加相应平台模块。
通过灵活调用 API 和事件监听,RTVoice 可快速集成到游戏对话、无障碍功能等场景中。


using Crosstales.RTVoice;
using Crosstales.RTVoice.Tool;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RtvoiceManger : Singleton<RtvoiceManger>
{
public SpeechText speechText;
/// <summary>
/// 外部调用转语音
/// </summary>
/// <param name="strin"></param>
public void Speaking(string strin)
{
speechText.Text = strin;
speechText.Speak();
}
//静音
public void Speaking_silence()
{
speechText.Silence();
Speaker.Silence();
}
}