Hi guys, i’m working on a script that register save and play audio from microphone.
I did almost all the only thing that i’ve to fix is the audio.Play();
this is my code:
private var buttonWidth = Screen.width * 0.2;
private var buttonHeight = Screen.width * 0.05;
private var buttonX = Screen.width *0.01;
private var buttonY = Screen.width *0.01;
private var micIn : boolean = false;
private var getAudioSource : AudioClip;
private var deviceName : String;
function Start() {
if(Microphone.devices.Length <= 0){
Debug.Log("Microphone not Connected");
}else{
micIn = true;
for(var i : int = 0; i < Microphone.devices.length; i++){
Debug.Log(Microphone.devices*);*
_ deviceName = Microphone.devices*;_
_ }_
_ } _
_}*_
function registerAudio() {
* Debug.Log(“Recording Audio”);*
* getAudioSource = Microphone.Start(deviceName , false, 10, 44100);*
}
function stopRecording(){
* Debug.Log(“Stop Recording”);*
* Microphone.End(deviceName);*
}
function saveAudio(){
* SavWav.Save(“registerAudio”, getAudioSource);*
}
function playAudio(){
* getAudioSource.Play();*
}
function OnGUI(){
* if(micIn){*
* if(!Microphone.IsRecording(deviceName)){*
* if(GUI.Button(Rect(buttonX,buttonY, buttonWidth, buttonHeight), “Record”)){*
* registerAudio();*
* }*
* }else{*
* if(GUI.Button(Rect(buttonX, buttonY, buttonWidth, buttonHeight), “Stop Recording”)){*
* stopRecording();*
* }*
* }*
_ if(GUI.Button(Rect(buttonX,buttonY+(buttonHeight1.2), buttonWidth, buttonHeight), “PlayAudio”)){_
_ playAudio();_
_ }*_
_ if(GUI.Button(Rect(buttonX, buttonY+((buttonHeight2)1.2), buttonWidth, buttonHeight), “SaveAudio”)){_
_ saveAudio();_
* }*
* if(Microphone.IsRecording(deviceName)){*
* GUI.Label(Rect(buttonWidth +50, 10, buttonWidth, buttonHeight), “Recording”);*
* }else{*
* GUI.Label(Rect(buttonWidth +50, 10, buttonWidth, buttonHeight), “Not Recording”);*
* }*
* }*
}
Two things i found:
if i add to getAudioSource, where microphone register audio datas , .clip i can play it but then i can’t save with SavWav class. there is any other way to play what i recorded without putting .clip to getAudioSource?