【问题标题】:No available audioEngine input channels when running on hardware在硬件上运行时没有可用的音频引擎输入通道
【发布时间】:2020-02-09 15:03:33
【问题描述】:

我正在尝试在我的 audioEngine 的 inputNode 上设置一个水龙头以进行语音识别。以下代码在模拟器中运行良好,但当我在运行 iOS 13.1.2 的 iPhone X 上运行时却不行。

以下是相关代码:

if (audioEngine == nil || (!audioEngine!.isRunning)) {
    print("Setting up audioEngine")
    if audioEngine == nil {
        audioEngine = AVAudioEngine.init()
    }

    if(audioEngine!.inputNode.inputFormat(forBus: 0).channelCount == 0){
        print("Not enough available inputs!")
    }

    let recognitionFormat = audioEngine!.inputNode.inputFormat(forBus: 0)
    audioEngine!.inputNode.installTap(onBus: 0, bufferSize: 1024, format: recognitionFormat) {
        (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
        self.recognitionRequest?.append(buffer)
    }
    audioEngine?.prepare()
    try audioEngine?.start()
}

我在模拟器中运行没有错误,语音识别工作正常。但是,在我的代码上运行时,我得到了以下信息:


Setting up audioEngine
[aurioc] AURemoteIO.cpp:1086:Initialize: failed: -10851 (enable 1, outf< 2 ch,      0 Hz, Float32, non-inter> inf< 2 ch,      0 Hz, Float32, non-inter>)
[aurioc] AURemoteIO.cpp:1086:Initialize: failed: -10851 (enable 1, outf< 2 ch,      0 Hz, Float32, non-inter> inf< 2 ch,      0 Hz, Float32, non-inter>)
Not enough available inputs!

如果我在channelCount == 0 之后没有返回,应用程序将崩溃:

[avae]            AVAEInternal.h:76    required condition is false: [AVAEGraphNode.mm:823:CreateRecordingTap: (IsFormatSampleRateAndChannelCountValid(format))]
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'

我的音频会话设置如下:

try audioSession.setCategory(.playAndRecord, options: [.defaultToSpeaker])
try audioSession.setActive(true)

对可用输入的检查产生:

LIST OF INPUTS: [<AVAudioSessionPortDescription: 0x280eac6b0, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Bottom>]

我被难住了。有什么帮助吗?

【问题讨论】:

标签: ios swift flutter avaudiosession


【解决方案1】:

我发现了问题所在。问题与 Flutter (这个应用程序正在使用,但我认为不相关)有关。事实证明它是相关的。显然FlutterAppDelegate@application 方法没有在主队列上运行,这是我开始我的AudioSession 的地方。当我像这样开始我的AudioSession 时,我的问题就消失了:

DispatchQueue.main.async {
    let audioSession = AVAudioSession.sharedInstance()
    do {
        try audioSession.setCategory(.playAndRecord, mode: .spokenAudio, options: .defaultToSpeaker)
        try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
    } catch {
        print("Failed to setup audio session")
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2014-01-19
    • 2011-01-21
    • 1970-01-01
    相关资源
    最近更新 更多