using NAudio.CoreAudioApi; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; using System; public class RecordEndPanel : MonoBehaviour { public Button okBtn; public Button anewBtn; public Button auditionBtn; public Button closeBtn; public Text timeText; public Text resultText; int number; string msg; public void Init(int number,string str,Action callback) { this.number = number; msg= str; resultText.text = str; timeText.text = MicrophoneInput.instance.recordTime+ "s"; okBtn.onClick.AddListener(()=> { Recognition(callback); }); anewBtn.onClick.AddListener(()=> { Anew(callback); }); auditionBtn.onClick.AddListener(Audition); closeBtn.onClick.AddListener(()=> { callback(false, "用户已停止语音识别"); RobotUI.Instance.ClosePanel(RobotePanelEnum.RecordEndPanel.ToString()); }); } /// /// 完成 /// private void Recognition(Action callback) { //回传数据 callback(true, msg); RobotUI.Instance.ClosePanel(RobotePanelEnum.RecordEndPanel.ToString()); } /// /// 重新录音 /// private void Anew(Action callback) { RobotUI.Instance.ClosePanel(RobotePanelEnum.RecordEndPanel.ToString()); RobotUI.Instance.OpenPanel(RobotePanelEnum.RecordPanel.ToString()).GetComponent().Init(number, callback); } /// /// 试听 /// private void Audition() { if (GameManager.current_component_type == ComponentType.无人机 || GameManager.current_component_type == ComponentType.数字人) { GameObject.Find("All").GetComponent().clip = MicrophoneInput.instance.audioSource.clip; GameObject.Find("All").GetComponent().Play(); } else { var rob = RobotManager.robots.Find(x => x.robot_id == number); rob.audioSource.clip = MicrophoneInput.instance.audioSource.clip; rob.audioSource.Play(); } } private void OnDisable() { okBtn.onClick.RemoveAllListeners(); anewBtn.onClick.RemoveAllListeners(); auditionBtn.onClick.RemoveAllListeners(); closeBtn.onClick.RemoveAllListeners(); } }