首页 > 解决方案 > 捕获音频时,我的 AVAudioEngine 似乎无法正常工作?

问题描述

我尝试使用 AVAudioEngine 来捕获音频并对其进行实时音频处理。

这是我在 Objective-c 中测试 installTapOnBus 方法的代码:

- (void)installTap:(AVAudioInputNode *)input {
    NSLog(@"Installing tap on bus 0.");
    AVAudioFormat *format = [input outputFormatForBus: 0];
    [input installTapOnBus:0 bufferSize:8192 format:format block:^(AVAudioPCMBuffer *buf, AVAudioTime *when) {
        NSLog(@"Get one buf");
    }];
}

- (void)setUpEngine {

    ...

    engine = [AVAudioEngine new];
    AVAudioInputNode *input = engine.inputNode;
    if([input inputFormatForBus:0].channelCount == 0) {
        NSLog(@"No enough available inputs!");
        return ;
    }
    [engine connect:input
                 to:engine.mainMixerNode
             format:[input inputFormatForBus:0]];
    NSThread *thread = [[NSThread alloc]initWithTarget:self
                                              selector:@selector(installTap:)
                                                object:input];
    [thread start];
    [engine prepare];
    [engine startAndReturnError:&error];
    if(error) {
        NSLog(@"Engine start error.");
    }
}

我认为如果它运行良好,它会在我的控制台上打印“Get one buf”。然后我在我的 iPhone8 上进行了测试,我确定麦克风权限已授予,但我没有在控制台上看到“Get one buf”。

我应该怎么做才能解决这个问题?

标签: iosobjective-cavaudioengine

解决方案


推荐阅读