iOS: Record audio in other format than caf - iphone

I am working on audio recording. I am able to record my audio in caf (Core audio format). Now I want to record sound in .mp3 or .amr.
I tried a lot of google but didn't found anything. I am not sure if my steps following work:
Write that Audio with .caf extention to document dir
Read data from that file
write the file again with .mp3 or .amr extention
I have 100% doubt that this will not going to work as this will just re save file with some other extension. This won't change audio codec.
I thought that for converting any format whether it is audio or video we need to change its codecs and data sequence.
Please also suggest me any player which don't play .caf files not anything else. So I can make sure that my files are converted successfully.
UPDATE Please also let me know that the way I am re-writing data with different extension is correct in the way I am needed?

You might be interested in the iPhoneExtAudioFileConvertTest example.
The MP3 format is however not available due to patents, maybe you can use LAME.

From the Document The Basics: Audio Codecs, Supported Audio Formats, and Audio Sessions

Related

Video Karaoke Development on iPhone

I have a karaoke app that takes mp3+g files and mixes in the mic (using audio units)... and is able to record the final results to a raw pcm file.
I have potential clients asking me if I can do the same with a karaoke video file. So, can I...
1) playback a video and mix in the microphone audio?
2) take #1 and record it to a video file?
3) possibly even take the video camera and microphone inputs, and video audio... and save this to a file?
Thinking about this can I... take an mp3, camera and microphone inputs and mix all of these to a video file?
Thanks for any feedback!
Brian
Yes, all of these are possible. With the CD+G format, you will be a lot better off converting those to h.264 on the desktop and then loading them as movies with an AAC audio track. Attempting to write a CD+G parser for iOS would be a nightmare since so many CD+G files are badly broken. Also, CD+G files are shocking large, much larger than the MP3 files because CD+G is dumb uncompressed video from the 80's. It is a silly format.

How to record mp4 file using AVCaptureSession?

I am recording .mov using AVCaptureMovieFileOutput with AVCaptureSession. I want to record .mp4 file, i guess it is not possible with AVCaptureMovieFileOutput, Any idea how to record .mp4 file?
Edit:
I have googled and found, there is a way AVAssetWriter, however it is not simple as AVCaptureMovieFileOutput?
thanks
There is one more way to record mp4 file, Actually its not recording, after recording with .mov we can convert that into mp4 file if we want. It is not the exact answer for the question, it may helps someone.

Can we slice an audio file(mp3 or any) into segments(parts of smaller size) programmatically in Xcode

I have a sound file which requires to be split into smaller parts. Is there any way i can do it, dividing an audio file into small slices of sound as Music Cutter does.
I also need to check that sliced parts can be played individually.
Any help will be appreciated.
Thanks
Vikas Ojha
It depends on the specific format of the file - an mp3 file, no - a wav file, yes.
For an mp3 file you would have to decompress the audio from the file first (you could use an audioqueue ), then split the raw audio data how ever you please, then re-encode each slice as mp3. Apple has sample code for decoding and encoding mp3's.
This is still not going to enable you to accept any input file format, for that you would need other external libraries, such as ffmpeg, LAME, etc. you might have to build these yourself and they may have disagreeable licensing restrictions.

Is it possible at all to record audio in AAC/MP4 format on the iPhone?

In this link it says it does:
http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html
However I have searched for an example that works on the web and can only see people complaining they can't get it to work. I have a working AudioQueue example for PCM but the very moment I switch this to AAC initialization fails. SpeakHere example also only uses PCM.
Has anyone ever managed to make this work or has a link to a code snippet that works?
Basically iPhone only record PCM. To get an AAC encoded file the original PCM stream should be stored into a AudioFile and then this AudioFile should be converted to AAC.
There's no way to record and convert on the fly on iPhone unless you include a third-party library that will do this for you.

Recording sound as WAV on iphone

I am making an iPhone recording app that needs to submit the sound file as a .wav to an external server.
Starting from the SpeakHere example, I am able to record sound as a file, but only as .caf
Does anyone know how to record it as a wav instead? Or how to convert from .caf to .wav on the iphone? (The conversion must happen on the phone)
EDIT:
I'm wondering if anything can be done with using kAudioFileWAVEType instead of kAudioFileCAFType in AudioFileCreateWithURL
Yup, the key is kAudioFileWAVEType
AudioFileCreateWithURL (
audioFileURL,
kAudioFileWAVEType,
&audioFormat,
kAudioFileFlags_EraseFile,
&audioFileID
);
Changing to WAVE from CAF in the SpeakHere example causes the recording to be as wav. I also edit the same thing in the playback class, and changed the filename to be Recording.wav
Have a look at libsndfile. It is a well used (including by Audacity) C library for working with lots of file formats. It supports read and write of a variety of CAF and WAV formats.
The CAF File structure and WAV format are fairly similar. If the worst comes to the worst, converting shouldn't be too hard.
It would involve taking the Audio data chunk, and copying as is into the WAV file, and using the information in the Audio Description Chunk to add an equivalent fmt subchunk for the WAV file. It is fairly simple byte copying.
However, be aware (as Eric pointed out) there are licensing issues, see: Can the Libsndfile library be used on the iPhone iOS?