5

有什么方法可以将我录制的 .WAV 文件转换为 iOS 中的 .M4A 文件?

而且我还必须将 .M4A 文件转换为 .WAV 文件。

我尝试使用音频队列服务,但我做不到。

4

2 回答 2

3

这篇文章:从 iPod 库到 PCM 样本的步骤比以前少得多,描述了如何从用户 ipod 库加载文件并将其作为线性 pcm (wav) 文件写入文件系统。

我相信您需要对代码进行更改以从文件系统加载文件,而不是在描述资产位置的 NSURL 中:

-(IBAction) convertTapped: (id) sender {
// set up an AVAssetReader to read from the iPod Library
NSURL *assetURL = [[NSURL alloc]  initFileURLWithPath:@"your_m4a.m4a"];
AVURLAsset *songAsset =
    [AVURLAsset URLAssetWithURL:assetURL options:nil];

NSError *assetError = nil;
AVAssetReader *assetReader =
    [[AVAssetReader assetReaderWithAsset:songAsset
           error:&assetError]
      retain];
if (assetError) {
    NSLog (@"error: %@", assetError);
    return;
}

如果您朝相反的方向前进,则需要更改输出端的格式:

NSDictionary *outputSettings =[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:2], AVNumberOfChannelsKey,
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)],
    AVChannelLayoutKey,
[NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
nil];

我不确定 m4a 的确切设置,但这应该让你更接近。

另一种选择是加载 ffmpeg lib 并在那里进行所有转换,但这似乎与您想要的不同。

于 2011-02-08T15:49:59.340 回答
0

TPAACAudioConverter工作正常

于 2011-09-08T19:08:54.620 回答