问题
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