具有可视化效果的音频录制 Mac 应用程序无法使用 AudioKit 选择输入设备

use*_*846 6 macos avfoundation avcapturesession avcapturedevice audiokit

嘿,我想知道是否有人可以指出我正确的方向。

我正在构建一个 Mac 音频应用程序,我需要执行以下操作

  • 选择音频输入设备
  • 显示设备输入的实时音频图(想想 GarageBand/Logic)
  • 捕获音频以进行重播
  • 输出声音或使其可选择作为另一个应用程序的输入设备 - 类似于 GarageBand Logic 等插件的工作方式

到目前为止,我已经研究过使用以下内容:

  • 音频套件
  • AVFoundation/AVCaptureDevice

AudioKit

这个框架看起来很棒,并且有我想做的大部分事情的示例应用程序,但是它似乎只接受 Mac 在设置中选择的音频输入。这对我来说是不可能的,因为我希望用户能够在应用程序中进行选择(就像 GarageBand 或 Neural Dsp 插件一样)

使用AudioEngine我可以获得可用的输入设备,但我发现的所有内容都表明它们在应用程序中不可更改 - 这是显示它们的代码

struct InputDevicePicker: View {
    @State var device: Device
    var engine: AudioEngine

    var body: some View {
        Picker("Input: \(device.deviceID)", selection: $device) {
            ForEach(getDevices(), id: \.self) {
                Text($0.name)
            }
        }
        .pickerStyle(MenuPickerStyle())
        .onChange(of: device, perform: setInputDevice)
    }

    func getDevices() -> [Device] {
        AudioEngine.inputDevices.compactMap { $0 }
    }

    func setInputDevice(to device: Device) {
      // set the input device on the AudioEngine
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

或者

AVFoundation

它有一个很好的 API,用于列出设备和设置输入,但是当涉及到处理委托提供的数据时,我不知道如何处理这个问题,即创建音频图并保存数据重播。这是委托方法供参考

extension Recorder: AVCaptureAudioDataOutputSampleBufferDelegate {

    func captureOutput(_ output: AVCaptureOutput,
                       didOutput sampleBuffer: CMSampleBuffer,
                       from connection: AVCaptureConnection) {

        print("Audio data recieved")
        // Needs to save audio here
        // Needs to play through speakers or other audio source
        // Need to show audio graph
    }
}
Run Code Online (Sandbox Code Playgroud)

如果有使用这些经验的人可以建议这是否可能以及我可以在哪里寻找示例/指导,那就太好了

任何帮助指示,救生员将不胜感激

如果您能走到这一步,谢谢!