views:

112

answers:

4

Hello, I'm using AVAudioRecorder to record audio from the iphone's mic but I want to discard the silence periods: start recording when detecting sound, and stop recording when next silence.

Can't figure out how to do that

Any advice?

Thanx!

A: 

Perhaps you could use the AVAudioRecorder's support for audio level metering to keep track of the audio levels and enable recording when the levels are above a given threshold. You'd need to enable metering with:

[anAVAudioRecorder setMeteringEnabled:YES];

and then you could periodically call:

[anAVAudioRecorder updateMeters];
power = [anAVAudioRecorder averagePowerForChannel:0];
if (power > threshold && anAVAudioRecorder.recording==NO) {
    [anAVAudioRecorder record];
} else if (power < threshold && anAVAudioRecorder.recording==YES) {
    [anAVAudioRecorder stop];
}

Or something like that.

Jake
Jake, thank you for the answer. Can't use metering as what it measures is average and peaks. If there is a mixed string of silences and audio input, it wont notice when theres a new silence after a silence-audio.
Martha
A: 

I've found the way based on Audio Queue Services. It is alot more complicated but alot more fun too as you define your queue buffers for the incoming audio packets.

You need to define the callback when the buffer if full, so you have the buffer full of packets that you can process as you wish, in my case to detect silence and a few more things.

Later having more time ill post the solution. If anyone urged that just cant wait drop me an email and ill be glad to help.

Check speakhere example here: http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html

Martha
A: 

Hi Martha,

I am also working on a app where i need to record audio and to stop when there is silence. I have been look all over but still could not find good solution for this. I am glad you have found a solution to detect the audio silence.

Unfortunately i am unable to send you a email request as or send a private message. Very much appreciate if you could post the solution.

I need to finish this up before deadline but ill update it with the answer asap. In the meantime check in the speakhere example AQRecorder class. AQRecorder::MyInputBufferHandler callback is called when buffer gets filled. There you will find audio packets described in inPacketDesc and timing, inBuffer->mAudioData. Packets with 0 value should be silence. Im recording from a device, but if you are recording from ambience should probably add a noise filter. Hope that helps.
Martha
A: 

Hi Martha,

Did you find a solution for this? I am looking for an answer on the same problem.

Thanks, Peter

FishEye