Reputation: 70997
I am using AVAudioRecorder in my app in order to create a .wav file based on user voice input. I want to be able to stuff" silence in the beginning of an audio file for some time before the actual recording is done.
How can I do this using AVAudioRecorder? Can I mention a time for which I want the "silence" to be recorded?
Thanks.
Upvotes: 0
Views: 416
Reputation: 2574
I haven't worked with the AVAudioRecorder in particular. But silence in PCM audio is just zeros as sample values. You could set the encoding of the AVAudioRecorder to PCM, store the file and then edit the file by prepending the desired number of zeros in the beginning. E.g. at 44100 Hz, 8-bit encoding, you'd add 44100 zero-bytes to the beginning of the file for each second of silence you would like to have. Hope this helps as an idea.
Note: Keep the file header of the PCM file intact and edit the "data chunk".
Upvotes: 1
Reputation: 2071
I'm sure there's probably a better way to do it, but how about simply pre-recording the silent stream you want and then concatenating that file with a file of the user generated content before saving out the final version?
Upvotes: 0