The file was successful created but you can't listen it from the inspector during the play. You must save your generated audioclip to be able to hear it from the inspector.
Create a new audioclip from GetData result in a muted sound
Hello everyone, I'm trying to create an audioclip from the microphone. I can record the clip, my scope is to create a new audioclip with the duration of the effective registration.
What I do is:
void createAudio(AudioClip recordedAudio, int positionStopRecord){
float[] samples = new float(recordedAudio.frequency * recordedAudio* channels);
float[] recordedSamples = new float (positionStopRecord * recordedAudio.Channels);
recordedAudio.getData(samples, 0);
AudioClip effectiveRecordedSound = AudioClip.Create("recordedAudio", positionStopRecord * recordedAudio.channels, recordedAudio.channels, recordedAudio.frequency, false);
for (int i = 0; i < recordedSamples.length; i++){
recordedSamples[i] = samples[i];
}
effectiveRecordedSound.SetData(recordedSamples, 0);
}
I got a new audioClip with the desired length but the audio is totally mute (and the line of the audioClip from the inspector is totally flat). The samples are the same, I even tried to do a simple copy (take the sample for audiosource a, create new audiosource, set the data from the same samples). The result is always the same.
Thanks for any help!
PS. The code is only an example but is the idea behind what I'm doing.