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!
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.
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
You can determine the background audio level by recording to a garbage file before you start recording for real:
AVAudioRecorder stops working when writing to /dev/null on iPhone 5s with iOS 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With