Record multiple AudioClip one after one and store then into an array.

Hi guys,

I tried to record some many AudioClips from a microphone, and store them in a array.
My problem is I can’t record, store in the first frame of an array, continue to record and store in the second frame of the array.

Like that :

Array[0] = first 5sec of record
Array[1] = 5sec to 5sec
Array[2] = 10sec to 15sec

My C# script looks like that at the moment :

using UnityEngine;
using System.Collections;

public class test_sound : MonoBehaviour {

	public AudioClip[] clips;
	
	void Start() {

		foreach (string device in Microphone.devices) {
			Debug.Log("Name: " + device);
		}
  		
		for (int i=0; i<5; i++) {
		     clips *= Microphone.Start("Microphone", true, 5, 44100);    			*
  •  }*
    
  •  audio.clip = clips[0];*
    
  •  audio.Play(2205); // 44100 = 1sec delay*
    
  • }*

  • void Update() {*

  •  }	*
    

}

I want to record one Clip at a time, not 5 clips together, how can I make that ?

Hey,

I solved my question today. I done this with a coroutine.
Here’s the script. If anyone has a better idea, I can waiting for.

using UnityEngine;
using System.Collections;

public class test_sound_2 : MonoBehaviour {
	
	public AudioClip[] clips;
		
	void Start() {
		
		foreach (string device in Microphone.devices) {
			Debug.Log("Name: " + device);
		}

		Debug.Log("Debut du premier enregistrement");
		StartCoroutine(WaitFunction());
	}

	IEnumerator WaitFunction() {

		for(int i =0; i<3; i++) {
			clips *= Microphone.Start("Microphone", true, 2, 44100);*
  •  	Debug.Log("Waiting 2 seconds");*
    
  •  	yield return new WaitForSeconds(2);*
    
  •  	Debug.Log("Done!");*
    
  •  	Debug.Log("Start other record");*
    
  •  }*
    
  •  yield return new WaitForSeconds(2);*
    
  •  Microphone.End("Microphone");*
    
  •  Debug.Log("Done!");*
    
  •  yield break;*
    
  • }*

  • void OnGUI(){*

  •  if(GUI.Button(new Rect(Screen.width/2-100, Screen.height/2-25, 200, 50), "Play sound 1"))* 
    
  •  {* 
    
  •  	audio.clip = clips[0];*
    
  •  	audio.Play ();*
    
  •  }* 
    
  •  if(GUI.Button(new Rect(Screen.width/2-100, Screen.height/2+25, 200, 50), "Play sound 2"))* 
    
  •  {* 
    
  •  	audio.clip = clips[1];*
    
  •  	audio.Play ();*
    
  •  }* 
    
  •  if(GUI.Button(new Rect(Screen.width/2-100, Screen.height/2+75, 200, 50), "Play sound 3"))* 
    
  •  {* 
    
  •  	audio.clip = clips[2];*
    
  •  	audio.Play ();*
    
  •  }* 
    
  • } *
    }
    Cheers !