87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
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<bool,string> 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());
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 完成
|
|
/// </summary>
|
|
private void Recognition(Action<bool,string> callback)
|
|
{
|
|
//回传数据
|
|
callback(true, msg);
|
|
RobotUI.Instance.ClosePanel(RobotePanelEnum.RecordEndPanel.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重新录音
|
|
/// </summary>
|
|
private void Anew(Action<bool, string> callback)
|
|
{
|
|
|
|
RobotUI.Instance.ClosePanel(RobotePanelEnum.RecordEndPanel.ToString());
|
|
RobotUI.Instance.OpenPanel(RobotePanelEnum.RecordPanel.ToString()).GetComponent<RecordPanel>().Init(number, callback);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 试听
|
|
/// </summary>
|
|
private void Audition()
|
|
{
|
|
if (GameManager.current_component_type == ComponentType.无人机 || GameManager.current_component_type == ComponentType.数字人)
|
|
{
|
|
GameObject.Find("All").GetComponent<AudioSource>().clip = MicrophoneInput.instance.audioSource.clip;
|
|
GameObject.Find("All").GetComponent<AudioSource>().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();
|
|
}
|
|
} |