【问题标题】:How to record my Mac's internal sound, not the microphone!, using AVCaptureSession?如何使用 AVCaptureSession 录制我的 Mac 的内部声音,而不是麦克风!
【发布时间】:2019-06-16 18:43:11
【问题描述】:

我正在尝试实现一个具有屏幕录制功能的简单 macOS 应用程序。

我不想录制麦克风输入,而是录制从我的 Mac 扬声器发出的声音。示例:这样我希望能够将 YouTube 视频录制到文件中。

这可以通过 AVCaptureSession 实现吗?谷歌搜索显示了捕获视频和微量的示例,但没有捕获内部音频。

这是我必须捕获视频和麦克风的工作代码。我必须修改哪些内容才能禁用麦克风并让扬声器发出内部 PC 的声音?

session = AVCaptureSession()
session.sessionPreset = AVCaptureSession.Preset.high

movieFileOutput = AVCaptureMovieFileOutput()

let displayId: CGDirectDisplayID = CGDirectDisplayID(CGMainDisplayID())

let audioDevice = AVCaptureDevice.default(for: .audio)!

let audioInput = try! AVCaptureDeviceInput(device: audioDevice)

let videoInput: AVCaptureScreenInput = AVCaptureScreenInput(displayID: displayId)!

session.addInput(videoInput)
session.addInput(audioInput)
session.addOutput(movieFileOutput)

session.startRunning()
movieFileOutput.startRecording(to: self.destinationUrl, recordingDelegate: self)

【问题讨论】:

    标签: swift macos avcapturesession


    【解决方案1】:

    我还没有找到一种简单的方法来做到这一点,但事实证明,如果我的机器上安装了另一个软件:Soundflower,则可以让原始代码录制音频。

    Soundflower 是 MacOS 的开源内核扩展,旨在创建一个虚拟音频输出设备,也可以作为输入。

    鉴于已安装 Soundflower,您可以使用 Applications / Utilities / Audio MIDI Setup 应用程序配置 macOS 以将音频发送到虚拟和真实音频设备。这样,上面的代码会从 Soundflower 捕获音频,但您仍然可以在普通音频输出设备上听到它。

    Applications / Utilities / Audio MIDI Setup 应用程序的设置如下所述:How can I send my computer's audio to multiple outputs?。

    【讨论】:

    • 我也解决了录制内部麦克风输入和回放录制的类似问题。见这里:Mac OS X Simple Voice Recorder.
    • iOS 有选项吗?
    • 很遗憾,我无法为 iOS 提供答案,因为我没有为 iOS 解决它。我只能猜测,对于 iOS,解决方案会完全不同,祝您研究顺利!
    • 不用担心,感谢您的回复!到目前为止,我的研究表明我将 AVAudioEngine 作为一个框架,但我仍在努力实现正确的实现。
    猜你喜欢
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多