using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VoiceInputs : MonoBehaviour
{
///
/// 录制的音频长度
///
public int m_RecordingLength = 5;
public AudioClip recording;
public bool IsRecording { get; private set; }
public event Action onRecordOver;
///
/// 开始录制声音
///
public void StartRecordAudio()
{
IsRecording = true;
recording = Microphone.Start(null, false, m_RecordingLength, 16000);
Debug.Log("开始录音...");
StartCoroutine(StopRecordAsync());
}
IEnumerator StopRecordAsync()
{
yield return new WaitForSeconds(m_RecordingLength);
StopRecordAudio();
}
///
/// 结束录制,返回audioClip
///
///
public void StopRecordAudio()
{
#if UNITY_WEBGL && !UNITY_EDITOR
signalManager.onAudioClipDone += _callback;
signalManager.StopRecordBinding();
#else
Microphone.End(null);
if(onRecordOver != null)
onRecordOver(recording);
IsRecording = false;
Debug.Log("停止录音");
#endif
}
}