【问题标题】:4 second lag in AVAudioRecorder recordAVAudioRecorder 记录延迟 4 秒
【发布时间】:2011-10-19 02:55:25
【问题描述】:

我正在使用 AVAudioRecorder 录制音频,但在按下按钮和开始录制之间出现 4 秒延迟。

这是我的设置代码:

NSDictionary *recordSettings = [NSDictionary 字典WithObjectsAndKeys:

                                    [NSNumber numberWithFloat: 16000.0],AVSampleRateKey,
                                    [NSNumber numberWithInt: kAudioFormatAppleIMA4],AVFormatIDKey,
                                    [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                    [NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,nil];

    NSError *error = nil;

    audioRecorder = [[AVAudioRecorder alloc]
                     initWithURL:soundFileURL
                     settings:recordSettings
                     error:&error];
    if (error)
    {
        NSLog(@"error: %@", [error localizedDescription]);

    } else {
        NSLog(@"prepare to record");
        [audioRecorder prepareToRecord];
    }

-(void)记录{

NSLog(@"Record");

//[audioRecorder prepareToRecord];

if (!audioRecorder.recording)

{

    NSLog(@"Record 2");

    [audioRecorder record];

    NSLog(@"Record 3");        

} 

}

记录是按下按钮时调用的函数。我知道 prepareToRecord 是通过“记录”隐式调用的,但我想看看它是否会影响延迟。它没有。

这是控制台日志:

2011-10-18 21:48:06.508 [2949:707] Record
2011-10-18 21:48:06.509 [2949:707] Record 2
2011-10-18 21:48:10.047 [2949:707] Record 3

在开始录制之前大约有 3.5 秒。

这些设置对于 iPhone 来说是不是太多了? (iPhone 4)。我是不是初始化错了?

【问题讨论】:

    标签: objective-c audio avaudiorecorder


    【解决方案1】:

    我在 iOS5/iPhone4 组合上看到了同样的问题。 iOS4 和 iPhone4S 都很好。在旧硬件上使用新操作系统时似乎存在问题。我也尝试了很多设置组合。

    在初始化录音机时尝试设置AVAudioSession 类别:

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

    【讨论】:

      【解决方案2】:

      我在第 4 代 iPod touch(iOS4、iOS5 和 JailBreak - 我使用了更多设备)上遇到了同样的问题,并且在不同的设备上运行不同,但我认为 @Charles Chase 是对的,它确实取决于设备的 iOS上测试。你的 recordSettings 字典没问题,代码看起来也不错,除了一件事,你需要添加这个:

      audioRecorder.delegate = self;
      

      在你分配和初始化你的记录器之后:

          audioRecorder = [[AVAudioRecorder alloc]
                                   initWithURL:soundFileURL
                                   settings:recordSettings
                                   error:&error];
      
          audioRecorder.delegate = self;
      

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题。此外,由于我在播放和录制模式之间切换,这会导致长时间的延迟。但是当我切换到播放和录制时,它拒绝使用 iPhone 上的扬声器,它只会使用耳机扬声器。

        解决方案:

        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
        UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
        AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute,
                                sizeof(audioRouteOverride), &audioRouteOverride);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-10-23
          • 2011-03-30
          • 1970-01-01
          相关资源
          最近更新 更多