开发者

How to record only the last 10 seconds of audio using AVAudioRecorder?

开发者 https://www.devze.com 2023-02-14 01:21 出处:网络
This might be a very simple request so apologies if it is. I\'m using AVAudioRecorder to record sound from the iphone\'s mic. Currently I\'m saving this to a file. The recording is only stopped once

This might be a very simple request so apologies if it is.

I'm using AVAudioRecorder to record sound from the iphone's mic. Currently I'm saving this to a file. The recording is only stopped once the user taps a button and is then played back.

My question is how would I get it so that the audio recorder only saves the last 10 seconds of sound?

I know I could probably get the player to only play fro开发者_C百科m the last 10 seconds but I don't want the recorded audio file to get huge. I'd prefer to just record the last 10 seconds.


Don't use the AVAudioRecorder API. It can't do what you want. Use the Audio Queue API (or maybe the RemoteIO Audio Unit) to record samples to a circular buffer 10 seconds long (that's less than 1 megabyte in size). Then unroll this circular buffer when writing the samples out to a .wav file following a WAVE/RIFF file header.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号