- Home /
Multiple Audiosources recording from the same microphone
I'm working on an app, it's supposed to be a mobile app, hence there's only one microphone available..
I'm wondering if I can use this single microphone to manipulate recordings of audioclips to different AudioSource objects.
I mean, in one case I may want one audiosource to constantly record for 20 seconds for example, while in the other audiosource I may want to start recording after 3 seconds, record for 10 seconds and then stop..
Is it possible to handle simultaneous recordings for 2 different audiosources in the same time and manipulate them independently from one another?
Answer by GKdev1980 · Feb 04, 2015 at 09:04 AM
I'm probably going to answer my own question after a few tests I made..
What I wanted to know if at any time a microphone is dedicated in recording to a single AudioClip or if it could record to multiple AudioClips at the same time. After trying the following code though:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
AudioSource aud;
AudioClip rec1;
AudioClip rec2;
void Start() {
Debug.Log ("Testing sound recording");
aud = GetComponent<AudioSource>();
rec1 = Microphone.Start(null, false, 5, 44100);
rec2 = Microphone.Start(null, false, 10, 44100);
}
void Update(){
if(Input.GetKeyUp(KeyCode.A) || Input.touchCount >0){
Debug.Log("Playing clip 1!!!");
aud.clip = rec1;
aud.Play();
}
else if(Input.GetKeyUp(KeyCode.B) || Input.touchCount >0){
Debug.Log("Playing clip 2!!!");
aud.clip = rec2;
aud.Play();
}
}
}
I get the feeling that this is not possible. I manage to play AudioClip 2, but when I try to play AudioClip 1 I get no sound.
I'll probably have to think of a different approach to what I have in mind...
Answer by beyonderic · Jul 01, 2018 at 06:57 PM
Any luck @abracadabra1980 ? I'm having the same issue.
Answer by Remjie · May 06, 2020 at 07:20 PM
I know it an old post but since nobody answer, maybe it could help. according to your own anwer, if you cant record 2 audioclip form same source ( i 'm asking the same that how i fall there), the workaround is to get the sound from the previous audioclip at defined time.
Here an exemple of what u could use :
private string mic = null;
private int micPos = 0;
private int samplerate = 16000;
private AudioClip GetAudioClip (AudioClip AC, int startPos)
{
micPos = Microphone.GetPosition(mic);
// be sure start pos is minimum 0
startPos = startPos < 0 ? 0 : startPos;
// clip lenght
int clipSize = micPos - startPos;
float[] clipSampleData = new float[clipSize];
// get sample from original clip
AC.GetData(clipSampleData, startPos);
// create a new one
AudioClip fullclip = AudioClip.Create("sample", clipSize, 1, samplerate, false);
// fill the new clip
fullclip.SetData(clipSampleData, 0);
return fullclip;
}
Your answer
Follow this Question
Related Questions
Microphone Noise Reduction speech enhancement 1 Answer
Microphone.GetComponent () not working + Microphone.devices empty? 0 Answers
Microphone capture different channels 0 Answers
Get volume from microphone to make something happen 0 Answers
Save Mic input and have it load when game starts up again 0 Answers