- Home /
Microphone recording problems (double sample, audiosource stops working)
Hi there
I'm using the microphone to record sound, attaching them to individual objects, and triggering those objects plays the recorded sound individually.
The mechanism is that the recording happens as long as the button is held down, and then it stops and truncate recording, and stores and assigns it to an object.
The problems: 1. The sound records twice, I think it as to do with my use of GetData and SetData but I'm not sure what's wrong. 2. After I record a sound, I activate the objects and they play their recorded sounds just fine. But then after a while it stops playing - not from the recorded object, nor from any other audiosources that has pre-recorded sounds in them that should work fine.
Here's the relevant code:
public List<AudioClip> customRecordings;
public AudioClip recordingClip;
public int currentRecording;
if (_recordButton.buttonClicked && !recording)
{
recording = true;
recordingClip = Microphone.Start (null, false, 60, 44100);
}
if (!_recordButton.buttonClicked && recording)
{
recording = false;
int lastSample = Microphone.GetPosition (null);
Microphone.End (null);
float[] tempSamples = new float[recordingClip.samples * recordingClip.channels];
recordingClip.GetData (tempSamples, 0);
recordingClip.SetData (tempSamples, lastSample);
customRecordings.Add (recordingClip);
// create sound module and pass audioclip to it
GameObject newSoundMod = Instantiate (SoundModulePrefab, new Vector3 (-1.133f, 1.271f, 0.074f), Quaternion.identity) as GameObject;
SoundModule newSoundModule = newSoundMod.GetComponent<SoundModule> ();
newSoundModule.SetAudioClip (customRecordings [currentRecording]);
newSoundModule.NotKinematic ();
newSoundModule.UpVolume ();
newSoundModule.MasterBlock = false;
currentRecording += 1;
}
Really not sure why those two problems are happening. Help? Thanks!!
Your answer
Follow this Question
Related Questions
Movement speed based on audio input 1 Answer
record dynamic length from microphone 1 Answer
Is it possible to select channels for the microphone input? 0 Answers
How to record audio in chunks and send through websocket? 0 Answers
Why I am getting Negative Decibels (around -70dB) where Normal Speech around 60dB 2 Answers