AVAudioEngine Microphone Crash on Start

女生的网名这么多〃 提交于 2019-12-11 15:08:14

问题


I'm trying to set up an AudioQueue to stream audio from the microphone on an iPhone.

I create my audio engine:

var audioEngine = AVAudioEngine()

And my audio queue:

    // Serial dispatch queue used to analyze incoming audio buffers.
    let analysisQueue = DispatchQueue(label: "com.apple.AnalysisQueue")


    // Install an audio tap on the audio engine's input node.
    audioEngine.inputNode.installTap(onBus: 0,
                                     bufferSize: 8192, // 8k buffer
                                     format: inputFormat) { buffer, time in

        // Analyze the current audio buffer.
        analysisQueue.async {
        }
    }

Whenever I run the code on the simulator or the device, I get the following crash:

*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: inputNode != nullptr || outputNode != nullptr'

I was following some Apple sample code while making this; somewhat confused. Any help appreciated!

EDIT: this question from a few days ago seems to point to a similar issue: AVAudioEngine.connect crash on hardware not simulator


回答1:


I somehow missed this thread while googling; but thanks to @SOreadytohelp I got it working -- just add

audioEngine.mainMixerNode

right above

do {
    // Start the stream of audio data.
    try audioEngine.start()
} catch {
    print("Unable to start AVAudioEngine: \(error.localizedDescription)")
}


来源:https://stackoverflow.com/questions/58495080/avaudioengine-microphone-crash-on-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!