我正在开发一个以 .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 格式录制音频。如果我想使用 keykAudioFormatMPEGLayer3(mp3)
而不是在 MP3 中录制音频,kAudioFormatLinearPCM(.wav)
我还需要进行哪些其他更改?recordSetting 字典中的变化,如采样率、通道和所有。
或者建议任何兼容 iPhone 和 Android 的音频格式,体积更小,可以直接从 iPhone 应用程序录制。