在我的可可应用程序中,我尝试记录来自内部麦克风的声音。我为此使用AVAudioRecorder类。在下面的代码中,我设置了AVAudioRecorder实例。

- (void)setupAudioRecorder {

    NSMutableDictionary *recordSettings = [NSMutableDictionary dictionary];

    recordSettings[AVFormatIDKey] = @(kAudioFormatLinearPCM);
    recordSettings[AVSampleRateKey] = @(16000.0);
    recordSettings[AVNumberOfChannelsKey] = @(1);
    recordSettings[AVLinearPCMBitDepthKey] = @(16);
    recordSettings[AVLinearPCMIsBigEndianKey] = @(NO);
    recordSettings[AVLinearPCMIsFloatKey] = @(NO);

    recordSettings[AVEncoderBitRateStrategyKey] = AVAudioBitRateStrategy_Variable;
    recordSettings[AVEncoderAudioQualityForVBRKey] = @(AVAudioQualityMedium);
    recordSettings[AVSampleRateConverterAlgorithmKey] = AVSampleRateConverterAlgorithm_Mastering;

    recordSettings[AVSampleRateConverterAudioQualityKey] = @(AVAudioQualityMedium);

    NSString *file = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)
                   objectAtIndex:0]
                  stringByAppendingPathComponent:@".recorder_voice.caf"];

    NSFileManager *fm = [NSFileManager defaultManager];

    if ([fm fileExistsAtPath:file])
        [fm removeItemAtPath:file error:nil];

    NSURL *url = [NSURL fileURLWithPath:file];
    NSError *err = nil;

    self.recorder.delegate = nil;
        self.recorder = [[AVAudioRecorder alloc] initWithURL:url
                                            settings:recordSettings
                                               error:&err];
    if(!self.recorder){
    // show error
    }

    [self.recorder setDelegate:self];
    [self.recorder prepareToRecord];

    self.recorder.meteringEnabled = YES;
}


在优胜美地,一切正常,但在小牛队,我却保持沉默。执行[self.recorder prepareToRecord]时,系统日志显示错误; :

AQMEIO.cpp:377 _FindIOUnit:错误-66680。

这是什么意思,我该如何解决?

最佳答案

终于我找到了答案。原因是在沙盒项目设置中。我没有在目标->功能->应用Sanbox中选中麦克风框。优胜美地忽略了这个问题,但Maverics却没有。

关于cocoa - AVAudioRecorder不在OS X Mavericks上录制,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31342042/

10-09 10:18