ict.lixian.single/Assets/Scripts/ROBOT/RecordKingPanel.cs

62 lines
1.8 KiB
C#

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<bool,string> 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();
}
/// <summary>
/// 点击停止录音
/// </summary>
private void StopRecordBtn(Action<bool,string> 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<RecordEndPanel>().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();
}
}