我在做录音。我可以用.caf (核心音频格式)录制我的音频,后来我需要将它转换为.wav或.wma,以便将文件上传到FTP服务器上。如何将文件转换为.wav或.wma格式的iOS格式?使用来自POVoiceHUD的GitHub代码。有人能帮我解决我的问题吗。
发布于 2016-08-08 08:27:56
首先,您必须将文件扩展名.caf更改为.wav,如下所示
[self.voiceHud startForFilePath:[NSString stringWithFormat:@"%@/Documents/MySound.wav", NSHomeDirectory()]]; 然后转到方法(startForFilePath:)中,更改语音质量的设置。
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:8000.0], AVSampleRateKey,
[NSNumber numberWithInt:8], AVLinearPCMBitDepthKey,
nil];发布于 2016-08-05 13:36:05
如果您想将.caf转换为.wav,那么您可以像我在注释中提到的那样引用这是如此的帖子。
但是,如果您希望您的音频作为.wav或.wma发送到服务器上或出于任何目的,那么为什么您从一开始就不以.wav或.wma格式录制音频。如果您要这样做,那么您将不需要转换它。
第二,您可以用.wav或.wma格式记录您的音频,只需将extension作为.wav或.wma提供给您的path或url,您将在那里存储您的视频,并将其传递给您的AVAudioRecorder对象。
例如,
NSString *folderPath = NSTemporaryDirectory();
NSString *soundFilePath = [folderPath
stringByAppendingPathComponent:[NSString stringWithFormat: @"%.0f%@", [NSDate timeIntervalSinceReferenceDate] *1000.0, @"audio.wav"]];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSLog(@"Using File called: %@",soundFileURL);
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSetting error:&error];
[audioRecorder setDelegate:self];
[audioRecorder prepareToRecord];更新:
我去过POVoiceHUd,
只要试着替换下面的线
[self.voiceHud startForFilePath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];使用
[self.voiceHud startForFilePath:[NSString stringWithFormat:@"%@/Documents/MySound.wav", NSHomeDirectory()]];我认为它将以.wav格式存储音频!
https://stackoverflow.com/questions/38790408
复制相似问题