7

I want to convert an audio file saved with .wav file format to a file with .mp3 format.

Please suggest that how can I achieve this through Objective C coding.

Thanks in advance.

iPhoneDev
  • 1,547
  • 2
  • 13
  • 36

5 Answers5

6

You'll have to use LAME to do this. Apple doesn't ship an MP3 encoder due to patent issues.

sbooth
  • 16,646
  • 2
  • 55
  • 81
  • I'm not sure if you mean the library or the executable but http://lame.cvs.sourceforge.net/viewvc/lame/lame/USAGE might help. – sbooth Feb 23 '12 at 11:11
  • http://stackoverflow.com/questions/9207063/how-can-i-compile-lame-as-static-library-a-for-armv6-and-armv7-of-iphone – William Power Apr 12 '13 at 08:18
4

Take a look at the AVFoundation framework, especially the AVAssetWriter class. It’s very powerful, but it takes some time to digest. There is a nice blog entry by Chris Adamson on decoding songs from the iPod library to PCM. It’s exactly the other way you want it, but it’s a good start.

zoul
  • 102,279
  • 44
  • 260
  • 354
  • Hi, I checked this link out. In this link its mentioned that we have to specify the output file type with AVAssetWriter.But there is no output file type for .mp3 format. Please check File Format UTIs in this link http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVFoundation_Constants/Reference/reference.html So my problem still remains the same. But thanks for the reply the blog entry is good. – iPhoneDev Feb 02 '11 at 10:13
  • I was assuming that any compressed format will do, sorry. In that case you would probably have to use some lower-level API rather than `AVFoundation`. – zoul Feb 02 '11 at 10:25
2

I don't think there is an API in AVFoundation for that. I think If you use AVAssetWritter you can write *.m4a (AVFileTypeAppleM4A) files which are *.acc, I believe. (ACC are lighter and better than mp3, so a good alternative to mp3)

If you use CoreAudio probably is going to be a lot much work but it should be possible to write mp3. I asked how to read mp3 using coreaudio in apple-lists like 2 years ago and I got code that makes speakHere sample app able to read *.mp3 ;)

Perhaps, you are interested: Newbie trying to play mp3 files instead wav files

nacho4d
  • 43,720
  • 45
  • 157
  • 240
  • Hi , thanks 4 replying, but I want to convert or create a sound file with .mp3 format. I know how to play .mp3 files. – iPhoneDev Feb 02 '11 at 10:15
0

Following on to sbooth's answer about LAME, there's a separate post on StackOverflow that gives you what you need to create a .a for the library: How can I compile lame as static library(.a) for armv6 and armv7 of iPhone?

Once you have done that, follow LAME's docs and you're set.

Community
  • 1
  • 1
William Power
  • 686
  • 7
  • 12
0

CoreAudio framework has an API called Extended Audio File Services, which enables converting from one format to another. See here: http://developer.apple.com/library/ios/#samplecode/iPhoneExtAudioFileConvertTest/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009222-Intro-DontLinkElementID_2

Itamar Katz
  • 9,544
  • 5
  • 42
  • 74