using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TextToSpeechHuman : MonoBehaviour { public Button att_startbtn; public Button att_stopbtn; public Text att_text; [SerializeField] AudioTest test; //文字转语音 public InputField tta_input; public Button tta_transbtn; public AudioSource tta_au; public Text stateText; [SerializeField] AudioData AudioData; public Dictionary audios_library = new Dictionary(); AudiosLibrary higth; public int volume; private void Awake() { for (int i = 0; i < AudioData.Conut(); i++) { audios_library.Add(AudioData.show(i).AudiosMan, AudioData.show(i)); } //AudiosLibrary tempau = new AudiosLibrary(); //tempau.AudiosMan2 = "x4_lingfeichen_assist"; //tempau.AudiosVolume = 100; //tempau.AudiosHigth = 10; //tempau.AudiosSpeed = 50; //audios_library.Add("重音", tempau); } // Start is called before the first frame update void Start() { //att_startbtn.onClick.AddListener(MicrophoneInput.instance.OnStartClick); //att_stopbtn.onClick.AddListener(() => //{ // MicrophoneInput.instance.OnStopClick((str) => // { // att_text.text = str; // tta_input.text = str; // ToAudio(); // }); //}); tta_transbtn.onClick.AddListener(() => { ToAudio("男重音", tta_input.text); }); } // Update is called once per frame void Update() { stateText.text = MyDebugger.msg; } private void ToAudio(string Selected,string tempStr) { if (!audios_library.ContainsKey(Selected)) { Debug.Log("声音类型设置错误,请检查字典列表"); return; } higth = new AudiosLibrary(); higth = audios_library[Selected]; higth.AudiosVolume = volume; if (tempStr.Length > 0) { //IFlytekManagerHuman.instance.TextToAudio(tempStr, clip => //{ // tta_au.clip = clip; // tta_au.Play(); //}, higth); } //Debug.Log(tta_au.clip.frequency); //Debug.Log(tta_au.clip.samples* tta_au.clip.channels); } }