【问题标题】:AVAudioRecorder Play the Recorded Item While Recording [duplicate]AVAudioRecorder 在录制时播放录制的项目[重复]
【发布时间】:2019-05-28 23:04:09
【问题描述】:

有没有一种方法可以播放在录制过程中正在录制的文件?也就是说,当用户插入带有麦克风的耳机时,当他对着麦克风说话时,他可以通过耳机听到自己的声音,这意味着无需担心循环。

附:如果AVAudioRecorder 不能做到这一点,有没有办法用AudioKit 做到这一点?如果是这样,请告诉我怎么做。

【问题讨论】:

    标签: ios swift avfoundation avaudiorecorder audiokit


    【解决方案1】:

    我猜你必须使用AVCaptureSession 来执行此操作。

    您可以从AVCaptureDeviceInput 获取输入。

    然后您可以使用AVCaptureOutputAudioDataOutput,它可以在录制音频样本缓冲区时访问它们。

    extension RecordingViewController: AVCaptureAudioDataOutputSampleBufferDelegate {
        func captureOutput(_ output: AVCaptureOutput,
                           didOutput sampleBuffer: CMSampleBuffer,
                           from connection: AVCaptureConnection) {
            output.connection(with: AVMediaType(rawValue: AVAudioSessionPortBuiltInSpeaker))
        }
    }
    

    编辑: 但是,使用 AudioKit 实现这一点可能更简单、更清晰。代码是这样的:

    let microphone = AKMicrophone()
    let mixer = AKMixer(microphone)
    let booster = AKBooster(mixer, gain: 0)
    AudioKit.output = booster
    
    microphone.start()
    do {
        try AudioKit.start()
    } catch {
        print("AudioKit boot failed.")
    }
    

    【讨论】:

    • 我认为 AudioKit 版本是我正在寻找的。谢谢!
    猜你喜欢
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 2012-01-14
    • 2011-02-06
    相关资源
    最近更新 更多