我正在为 iphone 6+ 开发录音应用。
问题1AVAudioRecorder)音频录制在模拟器中可以正常工作,但在设备中无法正常工作..
音频设置:
[settings setValue:[NSNumber numberWithInteger:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[settings setValue:[NSNumber numberWithFloat:44100.0f] forKey:AVSampleRateKey];
[settings setValue:[NSNumber numberWithInteger:1] forKey:AVNumberOfChannelsKey];
[settings setValue:[NSNumber numberWithInteger:AVAudioQualityLow] forKey:AVEncoderAudioQualityKey];
问题 2:麦克风在我的 ipad 上正常工作之前。但是当我使用这段代码时
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:&err];
麦克风在 ipad 中不工作.. 如何在 ipad/iphone 中重置或获取我的麦克风电平
Best Answer-推荐答案 strong>
在我的 - (void)setUpAudio 方法中,我创建了一个字典,其中包含 AVAudioRecorder 的设置。(它有点干净)您上面的代码几乎是正确的,但并不完全正确。见下文。
// empty URL
NSURL *url = [NSURL fileURLWithPath"/dev/null"];
// define settings for AVAudioRecorder
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithInt:AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
// init and apply settings
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
// This here is what you are missing, without it the mic input will work in the simulator,
// but not on a device.
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
error:nil];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
NSTimer *levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selectorselector(levelTimerCallback userInfo:nil repeats:YES];
[recorder record];
} else {
NSLog([error description]);
}
然后在更新方法中,您可以像这样跟踪您的麦克风输入电平。
- (void)levelTimerCallbackNSTimer *)timer {
[recorder updateMeters];
NSLog(@"Average input: %f Peak input: %f", [recorder averagePowerForChannel:0], [recorder peakPowerForChannel:0]);
}
如有任何问题或可以改进我的答案的方法,请告诉我。这里还是很新的。
关于iphone - AVAudioRecorder 如何在 iphone 中获得麦克风电平?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/18202694/
|