gpt4 book ai didi

swift AVAudioEngine : Changing the Audio Input Device for MacOS

转载 作者:行者123 更新时间:2023-11-28 07:38:40 28 4
gpt4 key购买 nike

我正在尝试更改用于收听传入音频的输入设备。我已经尝试了很多解决方案,但大多数在准备和启动音频引擎时都会出现以下错误:

AVAEInternal.h:82:_AVAE_CheckAndReturnErr: required condition is false: [AVAudioEngineGraph.mm:1295:Initialize: (IsFormatSampleRateAndChannelCountValid(outputHWFormat))]

当前(简化)代码:

var engine = AVAudioEngine()

var inputDeviceID: AudioDeviceID = 41 // another audio input device
let sizeOfAudioDevId = UInt32(MemoryLayout<AudioDeviceID>.size)
let error = AudioUnitSetProperty(engine.inputNode.audioUnit!, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &inputDeviceID, sizeOfAudioDevId)
if error > 0
{
print(error)
}

let inputNode = engine.inputNode
engine.connect(inputNode, to: engine.mainMixerNode, format: nil)
engine.connect(engine.mainMixerNode, to: engine.outputNode, format: nil)

engine.prepare()
do
{
try engine.start()
}
catch
{
print("Failed to start the audio input engine: \(error)")
}

audioDeviceId (41) 是正确的,因为使用随机数会产生不同的错误。

我做错了什么?

最佳答案

由于硬件问题,我无法正确测试您的代码。哪一行抛出错误?

你到底想达到什么目的?好久没看AVAudioEngine了,但觉得没必要连接内置引擎节点。至少不是输出。

来自docs对于 mainMixerNode:

When the property is first accessed the audio engine constructs a singleton main mixer and connects it to the outputNode on demand.

我还会尝试使用 node.outputFormat(forBus: 0) 检查有问题的节点的格式,并可能在建立连接时明确设置格式,如 this answer .

关于 swift AVAudioEngine : Changing the Audio Input Device for MacOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52818705/

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