gpt4 book ai didi

ios - 如何将 WAV 文件转换为 M4A?

转载 作者:可可西里 更新时间:2023-11-01 04:44:51 29 4
gpt4 key购买 nike

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

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

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

最佳答案

这篇文章:From iPod Library to PCM Samples in Far Fewer Steps Than Were Previously Necessary描述了如何从用户的 ipod 库加载文件并将其作为线性 pcm (wav) 文件写入文件系统。

我相信您需要对代码进行更改以从文件系统加载文件,而不是在描述 Assets 位置的 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 库并在其中进行所有转换,但这似乎与您想要的不同。

关于ios - 如何将 WAV 文件转换为 M4A?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4824980/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com