在采样处理程序中不返回麦克风声音

在采样处理程序中不返回麦克风声音

本文介绍了RPScreenRecorder startCaptureWithHandler:在采样处理程序中不返回麦克风声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在具有iOS 11.4的iPad上使用RPScreenRecorder startCaptureWithHandler:completionHandler:api直接捕获音频和视频.它可以很好地与应用程序屏幕,应用程序音频和摄像头配合使用,但是当我使用MikeEnabled = YES打开麦克风时,我在回调中从没收到麦克风的音频样本.

I am trying to use RPScreenRecorder startCaptureWithHandler:completionHandler: api on my iPad with iOS 11.4 to grab audio and video directly. It works well with the app screen, app audio and the camera, but when I turn on the microphone using microphoneEnabled = YES, I never get any audio sample for the mic in the callback.

我在info.plist中添加了麦克风隐私使用密钥,但这无济于事.

I added the microphone privacy usage key in the info.plist but that did not help.

我不确定接下来可以做什么来尝试解决此问题.

I am not sure what I can do next to try to resolve this issue.

谢谢.

推荐答案

此代码为我提供了包含实际麦克风音频的音频缓冲区(即使没有麦克风使用字符串或音频会话配置):

This code gets me audio buffers containing actual microphone audio (even without a microphone usage string or audio session configuration):

RPScreenRecorder *recorder = [RPScreenRecorder sharedRecorder];

recorder.microphoneEnabled = YES;

[recorder startCaptureWithHandler:^(CMSampleBufferRef sampleBuffer, RPSampleBufferType bufferType, NSError* error) {
    NSLog(@"Capture %@, %li, %@", sampleBuffer, (long)bufferType, error);
    if (RPSampleBufferTypeAudioMic == bufferType) {
        // Do something with mic audio
    }
} completionHandler:^(NSError* error) {
    NSLog(@"startCapture: %@", error);
}];

有一个权限对话框,询问您是否允许屏幕&麦克风,仅允许屏幕"或不允许".您是否可以仅点击屏幕? N.B.我不知道如何重置此对话框.

There's a permission dialog that asks whether you Allow Screen & Microphone, Allow Screen Only, or don't allow. Is it possible you tapped screen-only? N.B. I don't know how to reset this dialog.

另一种可能性是您要设置microphoneEnabled 开始捕获之后?那可能行不通.不,这对我也有用.

The other possibility is that you're setting microphoneEnabled after you start capturing? That might not work. Nah, that works for me too.

先前的猜测

您可能需要激活录音AVAudioSession:

try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryRecord)  // or AVAudioSessionCategoryPlayAndRecord!
try! AVAudioSession.sharedInstance().setActive(true)

这篇关于RPScreenRecorder startCaptureWithHandler:在采样处理程序中不返回麦克风声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 16:58