Question by
power_sandwich · Sep 10, 2015 at 03:18 PM ·
audiosourcesaveaudioclipwav
Save audioclip as wav/mp3/ogg...
Hello, I have this script which allows you to record your mic for 5 seconds, and then play it on the audiosource. I would like to save the audioclip created on the device I'm using. Is there a way to simply save the audioclip or do I have to convert the clip to something else (?)
Here is my code (you have to attach an audiosource on the object):
private var micPresence : boolean = false;
private var deviceName : String;
function Start() {
if(Microphone.devices.Length <= 0){ // check if there is at least 1 microphone
Debug.Log("No mic");
}else{
micPresence = true;
deviceName = Microphone.devices[0]; // 0 element is the default microphone
}
startRecording();
}
function startRecording() {
Debug.Log("Recording...");
GetComponent(AudioSource).clip = Microphone.Start(deviceName, true, 5, 44100);
yield WaitForSeconds(5);
stopRecording();
playClip();
}
function stopRecording(){
Debug.Log("Stopping...");
Microphone.End(deviceName);
}
function playClip(){
GetComponent(AudioSource).Play();
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612033228im_/https://answers.unity.com/themes/thub/images/avi.jpg)