当前位置:   article > 正文

Unity文字转语音(使用RT-Voice PRO [2023.1.0])_rtvoicepro添加其他声音

rtvoicepro添加其他声音

参考文章Unity插件——文字转朗读语音RtVioce插件功能/用法/下载_rtvoice-CSDN博客

一、使用步骤

1.导入进Unity(插件形式为 .unitypackage)

https://download.csdn.net/download/luckydog1120446388/88717512

2.添加所需Prefab

1).右键可以直接添加到 Hierarchy面板
在这里插入图片描述
2).添加后的样子
在这里插入图片描述

3.代码调用 RtVioceLocalTTS.cs

  1. using Crosstales.RTVoice;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /// <summary>
  7. /// creat by yxx
  8. ///
  9. /// https://blog.csdn.net/qq_43246529/article/details/109899257
  10. /// </summary>
  11. public class RtVioceLocalTTS : MonoBehaviour
  12. {
  13. /*
  14. 插件 - RtVioce
  15. 支持的Unity版本:5.3.1 及以上版本
  16. 功能:语音转文字
  17. *不需要为自己的声音行事
  18. *多个音色变换
  19. *多个扬声器 同时对讲(说话)
  20. *NPC聊天转换等。。。。
  21. ?生成的音频可以存储到文件中。*/
  22. public InputField mTxtSpeakContent;
  23. public Button mBtnClick;
  24. private string mID;
  25. // Start is called before the first frame update
  26. void Start()
  27. {
  28. mBtnClick.onClick.AddListener(() =>
  29. {
  30. //Speak(mTxtSpeakContent.text);
  31. mID = Speaker.Instance.Speak(mTxtSpeakContent.text, null, Speaker.Instance.Voices[0]);
  32. });
  33. }
  34. // Update is called once per frame
  35. void Update()
  36. {
  37. if (Input.GetKeyDown(KeyCode.P))
  38. {
  39. mID = Speaker.Instance.Speak("测试语音功能是否正常!Test whether the voice function is normal", null, Speaker.Instance.Voices[0]);
  40. //Speaker.Instance.SpeakNative("测试语音功能是否正常!Test whether the voice function is normal", Speaker.Instance.Voices[0], 1, 1, 1);
  41. Debug.Log("开始ID:" + mID);
  42. Speaker.Instance.OnSpeakStart += SpeakStart;
  43. Speaker.Instance.OnSpeakComplete += SpeakComplete;
  44. //Speaker.Instance.Speak("why");//测试语音功能是否正常!
  45. }
  46. if (Input.GetKeyDown(KeyCode.O))
  47. {
  48. Speaker.Instance.Silence(mID);
  49. mID = Speaker.Instance.Speak("我的目的是来测试id的", null, Speaker.Instance.Voices[0]);
  50. Debug.Log("开始ID:" + mID);
  51. Speaker.Instance.OnSpeakComplete += SpeakComplete;
  52. }
  53. if (Input.GetKeyDown(KeyCode.M))
  54. {
  55. Speaker.Instance.PauseOrUnPause();
  56. }
  57. if (Input.GetKeyDown(KeyCode.N))
  58. {
  59. Speaker.Instance.PauseOrUnPause();//
  60. }
  61. if (Input.GetKeyDown(KeyCode.Y))
  62. {
  63. Speaker.Instance.Silence(mID);//静默(介绍播放)
  64. }
  65. }
  66. private void SpeakStart(Crosstales.RTVoice.Model.Wrapper wrapper)
  67. {
  68. Debug.Log("开始播放ID:" + wrapper.Uid);
  69. }
  70. private void SpeakComplete(Crosstales.RTVoice.Model.Wrapper wrapper)
  71. {
  72. Debug.Log("完成ID:" + wrapper.Uid);
  73. if (wrapper.Uid.Equals(mID))
  74. {
  75. }
  76. }
  77. public void Speak(string _conetnt)
  78. {
  79. mID = Speaker.Instance.Speak(_conetnt, null, Speaker.Instance.Voices[0]);
  80. }
  81. /* public SpeechText SpeechText;
  82. // Start is called before the first frame update
  83. void Start()
  84. {
  85. *//* Speaker.Speak("哇塞,我可以说话了!", null, null, true, GUISpeech.Rate, GUISpeech.Volume, "", GUISpeech.Pitch);
  86. Speaker.OnSpeakComplete += speakEndMethod;
  87. Speaker.OnSpeakStart += speakStartMethod;*//*
  88. //取消调用
  89. //Speaker.OnSpeakStart-= speakStartMethod;
  90. //Speaker.OnSpeakComplete += speakEndMethod;
  91. //Speaker.Silence();//停止说话
  92. }
  93. private void speakStartMethod()//SpeakEventArgs e)
  94. {
  95. print("开始说话");
  96. }
  97. private void speakEndMethod()//SpeakEventArgs e)
  98. {
  99. print("完成说话");
  100. }
  101. // Update is called once per frame
  102. void Update()
  103. {
  104. if (Input.GetKeyDown(KeyCode.A))
  105. {
  106. SpeechText.Speak();
  107. }
  108. }*/
  109. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/268982
推荐阅读
相关标签
  

闽ICP备14008679号