Save audio in caf format to wav format
I record audio in .caf format and later need to convert it to .wav in order to send the file as a email attachment. How can I convert the file to wav format in iOS 3.1.x?
The format of the audio:
[NSNumber 开发者_开发知识库numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithFloat:11025.0f], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:YES], AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey,
I am not tied to this format, I just need to be able to record and playback on the device and email a wav version file.
The answer is simple, just init with a .wav extension.
The answer was provided by Paul Bruneau on the Apple Developer forum:
From the class reference docs, the recorder infers the file type from the extension that you choose. So try .aiff or .aif or .wav
initWithURL:settings:error: Initializes and returns an audio recorder.
- (id)initWithURL:(NSURL *)url
settings:(NSDictionary *)settings
error:(NSError **)outError
Parameters: url
The file system location to record to. The file type to record to is inferred from the file extension included in this parameter’s value.
The Bad:
I don't think there is any "automatic" way to do this wit the iPhone, meaning you have to do it yourself - manually.
The Good:
It is very very simple to do. A WAV file - assuming your just talking about using raw, uncompressed audio - is just a header you need to stick on the beginning of the audio data. The format is very simple. There are numerous references on the web:
http://www.sonicspot.com/guide/wavefiles.html
The Ugly:
I am not farmiliar with the source format you are talking about. If it is uncompressed, great. If not, you may need to uncompress it. WAV files also have methods to store compressed data, so if your data source is compressed, then you might be able to store it as such in the WAV by generating new headers and indicating it compressed as such.
Also - by "compressed" - I mean in any codec other than standard X-bit Y-Channel PCM.
精彩评论