using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; public class RecordKingPanel : MonoBehaviour { public Button stopRecordBtn; public Button closeBtn; public Text timeText; int number; public void Init(int number,Action callback) { this.number = number; timeText.text = "0s"; stopRecordBtn.onClick.AddListener(()=> { StopRecordBtn(callback); }); closeBtn.onClick.AddListener(()=> { MicrophoneInput.instance.StopRecord(); callback(false, "用户停止录音"); RobotUI.Instance.ClosePanel(RobotePanelEnum.RecordKingPanel.ToString()); }); //开始录音 MicrophoneInput.instance.OnStartClick(); } /// /// 点击停止录音 /// private void StopRecordBtn(Action callback) { int length = MicrophoneInput.instance.StopRecord(); Debug.Log("录音返回长度:" + length); if (length > 0) { MicrophoneInput.instance.TransToText(str => { Debug.Log("AAAAAAAAAAAA " + str); //打开识别页面 RobotUI.Instance.OpenPanel(RobotePanelEnum.RecordEndPanel.ToString()).GetComponent().Init(number, str,callback); RobotUI.Instance.ClosePanel(RobotePanelEnum.RecordKingPanel.ToString()); }); } } // Update is called once per frame void Update() { if (Microphone.IsRecording(null)) { timeText.text = MicrophoneInput.instance.recordTime + "s"; } } private void OnDisable() { stopRecordBtn.onClick.RemoveAllListeners(); } }