- Home /
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[i] = 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 ?
Answer by Zeterro · Jan 20, 2014 at 10:24 AM
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[i] = 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 !
Your answer
Follow this Question
Related Questions
Store multiple random integers in an array? 4 Answers
How To Take a Randomly Generated Name And Add it as well as some values to a nested Dictionary? 1 Answer
Is this doable in unity 2 Answers
Getting variables of objects in an array, then adding them together 1 Answer
Why does my program crash when allocate and try to store variable in Vector3 array? 1 Answer