【发布时间】:2012-05-11 09:43:55
【问题描述】:
我正在开发一个以 .wav 格式录制音频的 iPhone 应用程序。
代码如下:
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc]init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:11025.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
NSString *myDBnew = [documentsDirectory stringByAppendingPathComponent:@"test.wav"];
recordedTmpFile = [NSURL fileURLWithPath:myDBnew];
NSLog(@"Using File called: %@",recordedTmpFile);
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
以上代码是以 .wav 格式录制音频。如果我想使用键 kAudioFormatMPEGLayer3(mp3) 而不是 kAudioFormatLinearPCM(.wav) 在 MP3 中录制音频,我还需要进行哪些其他更改?采样率、通道等记录设置字典的变化。
或者建议任何兼容 iPhone 和 Android 的音频格式,体积更小,可以直接从 iPhone 应用程序录制。
【问题讨论】:
标签: iphone objective-c ios avaudioplayer avaudiorecorder