Recording sound as WAV on iphone

亡梦爱人 提交于 2020-01-09 13:07:25

问题


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


回答1:


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




回答2:


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?



来源:https://stackoverflow.com/questions/570430/recording-sound-as-wav-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!