将caf格式的音频保存为wav格式

时间:2022-05-08 19:42:55

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?

我以.caf格式录制音频,稍后需要将其转换为.wav,以便将文件作为电子邮件附件发送。如何在iOS 3.1.x中将文件转换为wav格式?

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.

我不依赖于这种格式,我只需要能够在设备上录制和播放并通过电子邮件发送wav版本文件。

2 个解决方案

#1


4  

The answer is simple, just init with a .wav extension.

答案很简单,只是带有.wav扩展名的init。

The answer was provided by Paul Bruneau on the Apple Developer forum:

答案由Paul Bruneau在Apple Developer论坛上提供:

From the class reference docs, the recorder infers the file type from the extension that you choose. So try .aiff or .aif or .wav

从类引用文档中,记录器从您选择的扩展名中推断出文件类型。所以试试.aiff或.aif或.wav

initWithURL:settings:error: Initializes and returns an audio recorder.

initWithURL:settings:error:初始化并返回录音机。

- (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.

要记录到的文件系统位置。要记录的文件类型是从此参数值中包含的文件扩展名推断出来的。

#2


2  

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.

我不认为有任何“自动”方式与iPhone一起做这件事,这意味着你必须自己动手 - 手动。

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:

这样做非常简单。一个WAV文件 - 假设你刚才谈论使用原始的,未压缩的音频 - 只是你需要坚持音频数据开头的标题。格式非常简单。网上有很多参考文献:

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.

我对你所谈论的源格式并不熟悉。如果没有压缩,那很好。如果没有,您可能需要解压缩它。 WAV文件还有存储压缩数据的方法,因此如果您的数据源是压缩的,那么您可以通过生成新的标头并指示它如此压缩来将其存储在WAV中。

Also - by "compressed" - I mean in any codec other than standard X-bit Y-Channel PCM.

另外 - 通过“压缩” - 我的意思是在标准X位Y通道PCM之外的任何编解码器中。

#1


4  

The answer is simple, just init with a .wav extension.

答案很简单,只是带有.wav扩展名的init。

The answer was provided by Paul Bruneau on the Apple Developer forum:

答案由Paul Bruneau在Apple Developer论坛上提供:

From the class reference docs, the recorder infers the file type from the extension that you choose. So try .aiff or .aif or .wav

从类引用文档中,记录器从您选择的扩展名中推断出文件类型。所以试试.aiff或.aif或.wav

initWithURL:settings:error: Initializes and returns an audio recorder.

initWithURL:settings:error:初始化并返回录音机。

- (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.

要记录到的文件系统位置。要记录的文件类型是从此参数值中包含的文件扩展名推断出来的。

#2


2  

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.

我不认为有任何“自动”方式与iPhone一起做这件事,这意味着你必须自己动手 - 手动。

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:

这样做非常简单。一个WAV文件 - 假设你刚才谈论使用原始的,未压缩的音频 - 只是你需要坚持音频数据开头的标题。格式非常简单。网上有很多参考文献:

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.

我对你所谈论的源格式并不熟悉。如果没有压缩,那很好。如果没有,您可能需要解压缩它。 WAV文件还有存储压缩数据的方法,因此如果您的数据源是压缩的,那么您可以通过生成新的标头并指示它如此压缩来将其存储在WAV中。

Also - by "compressed" - I mean in any codec other than standard X-bit Y-Channel PCM.

另外 - 通过“压缩” - 我的意思是在标准X位Y通道PCM之外的任何编解码器中。