記得還要在此程式碼外部加入 "Audio Source" 元件喔!!

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();
            }
        }
    }
 
}
 
 
 
 
 
 
文章標籤
全站熱搜
創作者介紹
創作者 黃彥霖 的頭像
黃彥霖

彥霖 實驗筆記

黃彥霖 發表在 痞客邦 留言(4) 人氣(2,148)