Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 291
matt Avatar asked Feb 20 '09 17:02

matt


People also ask

Can I record a WAV file on my iPhone?

To record a WAV file on iPhone, you need a good WAV recorder app to back you up with a WAV file format. Hokusai Audio Recorder is a beneficial, easy-to-use, and flexible app to create WAV files for you on your iPhone. It can save WAV or M4A audio files and convert M4A or other audio files to WAV format.

What format is iPhone audio recording?

The MPEG-4 codec used to record and play back audio files in the iPhone's Voice Memo app is compressed using the Advanced Audio Coding (AAC) codec or the Apple Lossless Audio Codec (ALAC). Because the Voice Memo app only records audio data, the ". M4A" file extension is used, rather than the ". MP4" file extension.

Does iPhone use WAV or MP3?

Apart from the AAC, Apple Lossless and MP3, iPhone can directly play WAV files. It's weird that, however, sometimes iPhone and other iOS mobile devices won't play . wav files as expected. It is a quite common phenomenon that many people have submitted complaints on official community, just like Android won't play WAV.


2 Answers

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

like image 89
matt Avatar answered Sep 18 '22 16:09

matt


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?

like image 41
Nick Fortescue Avatar answered Sep 21 '22 16:09

Nick Fortescue