private int Frequency = 16000; //录音频率
private int BitRate = 16; //比特率
private int MicSecond = 2; //每隔2秒,保存一下录音数据
public Button bStart;
public Button bStop;
public Button bPlay;
public Text tTip;
public AudioSource au;
void Start () {
bStart.onClick.AddListener(OnStartClick);
bStop.onClick.AddListener(OnStopClick);
bPlay.onClick.AddListener(OnPlayClick);
}
void OnStartClick()
{
tTip.text += "\n开始录音....";
au.Stop();
au.loop = false;
au.mute = true;
au.clip = Microphone.Start(null, true, MicSecond, Frequency);
}
void OnStopClick()
{
tTip.text += "\n停止录音!";
if (!Microphone.IsRecording(null))
return;
Microphone.End(null);
au.Stop();
Mp3FromClip("d:/test.mp3", au.clip); //将录音保存为mp3
//WavFromClip("d:/test.wav", au.clip); //将录音保存为wav
}
void OnPlayClick()
{
if (Microphone.IsRecording(null