gpt4 book ai didi

ios - AVAudioEngine 麦克风启动时崩溃

转载 作者:行者123 更新时间:2023-11-29 05:22:52 30 4
gpt4 key购买 nike

我正在尝试设置一个 AudioQueue 以从 iPhone 上的麦克风传输音频。

我创建我的音频引擎:

var audioEngine = AVAudioEngine()

还有我的音频队列:

    // 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 {
}
}

每当我在模拟器或设备上运行代码时,都会出现以下崩溃:

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

我在制作这个时遵循了一些苹果示例代码;有点困惑。任何帮助表示赞赏!

编辑:几天前的这个问题似乎指向类似的问题:AVAudioEngine.connect crash on hardware not simulator

最佳答案

我在谷歌搜索时不知何故错过了这个线程;但感谢@SOreadytohelp,我让它工作了——只需添加

audioEngine.mainMixerNode

正上方

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

关于ios - AVAudioEngine 麦克风启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58495080/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com