記得還要在此程式碼外部加入 "Audio Source" 元件喔!!
using UnityEngine;
using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {
bool isRecord = true;
void OnGUI(){
if(isRecord){
if(GUI.Button(new Rect(Screen.width/2-100, Screen.height/2-50,200,100), "Record")){ // 開始錄音
isRecord = !isRecord;
audio.clip = Microphone.Start("MyMicrophone", true, 1000, 44100); // 錄音1000秒,44100 Hz 格式
}
}else{
// 暫停錄音,並撥放錄音
if(GUI.Button(new Rect(Screen.width/2-100, Screen.height/2-50,200,100), "Close & Play")){
isRecord = !isRecord;
Microphone.End("MyMicrophone");
audio.Play();
}
}
}
}
文章標籤
全站熱搜

*****
*****
*****
大大你好 我可以請教一下 假如我要把錄完音的檔案留下來 要怎麼寫呢?