启动时AVAudioEngine麦克风崩溃 [英] AVAudioEngine Microphone Crash on Start

查看:153
本文介绍了启动时AVAudioEngine麦克风崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set up an AudioQueue to stream audio from the microphone on an 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 {
        }
    }

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

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'

在进行此操作时,我遵循了一些Apple示例代码;有点困惑.任何帮助表示赞赏!

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

EDIT :几天前的这个问题似乎指向类似的问题:

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

推荐答案

我在谷歌搜索时以某种方式错过了该线程;但是多亏了@SO​​readytohelp,我才能正常使用-只需添加

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

audioEngine.mainMixerNode

右上方

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

这篇关于启动时AVAudioEngine麦克风崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆