0

I'm using Audio Queue to record audio from the iphone's mic and stop recording when silence detected (no audio input for 10seconds) but I want to discard the silence from audio file.

In AudioInputCallback function I am using following code to detect silence :

AudioQueueLevelMeterState meters[1];
UInt32 dlen = sizeof(meters);
OSStatus Status AudioQueueGetProperty(inAQ,kAudioQueueProperty_CurrentLevelMeterDB,meters,&dlen);
if(meters[0].mPeakPower < _threshold)
{ // NSLog(@"Silence detected");}

But how to remove these packets? Or Is there any better option?

Sicco
  • 6,167
  • 5
  • 45
  • 61
user1495653
  • 133
  • 1
  • 1
  • 8

2 Answers2

2

Instead of removing the packets from the AudioQueue, you can delay the write up by writing it to a buffer first. The buffer can be easily defined by having it inside the inUserData.

When you finish recording, if the last 10 seconds is not silent, you write it back to whatever file you are going to write. Otherwise just free the buffer.

vgrimmer
  • 165
  • 2
  • 12
0

after the file is recorded and closed, simply open and truncate the sample data you are not interested in (note: you can use AudioFile/ExtAudioFile APIs to properly update any dependent chunk/header sizes).

justin
  • 104,054
  • 14
  • 179
  • 226