Record audio on iPhone with smallest file size - iphone

I want to record audio with iPhone and then upload it to server.
I could record the audio, but my question is about which format should I use to record audio, so that the Recorder will result a file with smallest file size.

Here are the results for few encoding supported by iPhone. Size of audio file in KB of duration 10 sec.
kAudioFormatMPEG4AAC : 164,
kAudioFormatAppleLossless : 430,
kAudioFormatAppleIMA4 : 475,
kAudioFormatULaw : 889,
kAudioFormatALaw : 889,
Among these kAudioFormatMPEG4AAC is having smallest size.

Apple iOS supports playback audio in these formats:
AAC (MPEG-4 Advanced Audio Coding)
ALAC (Apple Lossless)
HE-AAC (MPEG-4 High Efficiency AAC)
iLBC (internet Low Bitrate Codec, another format for speech)
IMA4 (IMA/ADPCM)
Linear PCM (uncompressed, linear pulse code modulation)
MP3 (MPEG-1 audio layer 3)
µ-law and a-law
For recording following formats are possible:
AAC (MPEG-4 Advanced Audio Coding)
ALAC (Apple Lossless)
iLBC (internet Low Bitrate Codec, for speech)
IMA4 (IMA/ADPCM)
Linear PCM (uncompressed, linear pulse-code modulation)
µ-law and a-law
while only AAC supports hardware-assisted encoding (see Apple iOS SDK documentation)
For the universality in availability I prefer MP3.
Check these links to find exact code to record audio - Recording Audio on an iPad with AVAudioRecorder

It depends on the type of audio you are recording and the audio quality you want.
If for example, you are recording voice with the built in mic, iLBC will give you the smallest audio file (15.2 kbit/s for 20 ms frames, 13.33 kbit/s for 30 ms frames).

Related

Rendered audio plays in slow-mo

When decoding the audio data of an mp3 file I fetched, rendering it with my OfflineContext, and exporting it back to a .wav file, the sound is in slo-mo with a different pitch. Is it because the sample rates of my mp3 file and OfflineContext are different? If it is, how can I export the mp3 file in a different sample rate while not changing the pitch?
Edit:
I run decodeAudioData with the OfflineAudioContext that I use for the rendering: offlineContext.decodeAudioData(this.arrayBuffer). The sample rate of offlineContext is 48000, while the sample rate of my audioContext (used for normal playback, which works well) is 41000.
While creating the WAV file, the same sample rate than the offline context should be set in the WAV file header. For example, a WAV file with a sample rate of 44100 in the header that contains data chunks with a sample rate of 48000 will cause the playback to be in "slow motion" in iTunes.

how to record only audio using UIImagePickerController?

I am working on media recording on IOS. I was able to record with both audio and video using UIImagePickerController. For my specification I want to record only audio. Is it possible with UIImagePickerController? or Do I need to think about other methods?
thanks.
UIImagePickerController cannot be used to record audio. Instead you should take a look at the SpeakHere sample code from Apple.
Also check Audio Queue - Recording to a compressed audio format on how to record as compressed audio format and conserve disk space.

.caf vs .wav in iOS application

I'm using cocos2d and it is possible to play both formats using SimpleAudioEngine (obviously did not tried .caf) What format is preferable and why ?
I recommend you to use caf format with IMA4 compression for sound effects and aac for BGM.
CocosDenshion FAQ - What sound formats can I use?
For sound effects played with
CDSoundEngine it is recommended to use
16 bit mono wave files for
uncompressed audio and IMA4 for lossy
compressed audio. IMA4 sounds are
around one quarter the size of the
corresponding wave file.
How do I choose the best audio formats in iPhone OS?

iPhone game audio and background music

Have a few questions related to adding sounds to my game, specifically intro music (for splash), background music (loop) and button event sounds. Hope you can share your knowledge on this.
1) Should I use compressed sounds or uncompressed sounds? Or perhaps a combination of the two? Are there any limitations on the iPhone hardware that I should be aware of -- for example, the ability to play multiple compressed sounds?
2) What's the best audio format for my purpose?
3) For background music, I am thinking of using AVAudioPlayer. For button event sounds, I am thinking of using AudioServicesPlaySystemSound, what do you think?
4) Any other issues I should be aware of?
Thank you!
1) According to the iPhone Application Programming Guide: "Starting in iPhone OS 3.0, nearly all supported audio formats can be used for simultaneous playback—namely, all those that can be played using software decoding, as described in Table 7-1. For the most processor-efficient multiple playback, use linear PCM (uncompressed) or IMA4 (compressed) audio."
But if you're going to be playing a lot of sounds at the same time, you should use either uncompressed or IMA4.
2) You should use the CAF file format because it gives you the most flexibility in what data format to use. You can put MP3, AAC, PCM, IMA4, and pretty much any compressed or uncompressed data in a CAF file (.caf). I typically use CAF files with IMA4 compression at mono, 16-bit, 44.1kHz.
3) That's how I do it in my apps: AVAudioPlayer for voice cues that cause the music levels to duck, and AudioServicesPlaySystemSound for buttons and other UI sound effects.
4) If you use uncompressed PCM data, the file sizes can be huge, but IMA4 is a fairly noisy compression scheme. You can use AAC but then you might be limited by how many AAC sounds you can play at once. Before iPhone OS 3.0, you could only play one AAC or MP3 sound at a time.

Which format support the audio file with a playing video?

i am playing the video and in the background i have to play the audio file and if i do this audio is not playing its sound as it just play video is it a extension problem i am using the .mp3 for the audio and .mp4 for the video .
how can we do this we have to play simultanisouly .both the file
balraj verma
Have a look at this:
http://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/CoreAudioOverview/CoreAudioEssentials/CoreAudioEssentials.html#//apple_ref/doc/uid/TP40003577-CH10-SW67
"To play multiple sounds simultaneously, create one playback audio queue object for each sound. For each audio queue, schedule the first buffer of audio to start at the same time using the AudioQueueEnqueueBufferWithParameters function.
Audio format is critical when you play sounds simultaneously on iPhone or iPod touch. This is because playback of certain compressed formats in iPhone OS employs an efficient hardware codec. Only a single instance of one of the following formats can play on the device at a time:
AAC
ALAC (Apple Lossless)
MP3"