RT-Voice是Unity中的插件,提供了强大的文字朗读功能,支持多种语言和方言,具备自然的语音合成技术,允许动态生成语音内容,帮助开发者轻松为应用程序添加多样化的语音体验,从而提升用户体验,增强应用程序的交互性,以满足全球用户的语言需求。

导入unitypackage包后,我们添加预制体即可:

其实只用到了RTVoice。

参考支持中文的代码:

using Crosstales.RTVoice;
using Crosstales.RTVoice.Tool;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
using Crosstales.RTVoice.Model;
using UnityEngine.EventSystems;

public class speechTest : MonoBehaviour
{
    public AudioSource SourceA;
    // Start is called before the first frame update
    void Start()
    {
        Speaker.Instance.OnSpeakAudioGenerationComplete += speakAudioGenerationCompleteMethod;

    }
    private Wrapper currentWrapper;
    private void speakAudioGenerationCompleteMethod(Wrapper wrapper)
    {

        currentWrapper = wrapper;

        Invoke(nameof(speakAudio), 0.1f); //needs a small delay
    }
    private void speakAudio()
    {
        Speaker.Instance.SpeakMarkedWordsWithUID(currentWrapper);
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            Speaker.Instance.Speak("姑苏城外寒山寺", SourceA,
                Speaker.Instance.VoiceForGender(Crosstales.RTVoice.Model.Enum.Gender.FEMALE, "zh", 0, "zh"),
                true, 1.25f);
        }
    }
}

我的电脑不知道为什么,必须这么搞一下,才能说中文,否则直接输出会不读中文的

隐藏内容
本内容需权限查看
  • 普通用户: 不可购买
  • 会员: 免费
  • 永久会员: 免费
已有4人解锁查看

更多资源在浮云居

 

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。