gpt4 book ai didi

ios - 将 AVAudioMixerNode 连接到 AVAudioEngine

转载 作者:行者123 更新时间:2023-12-01 15:34:20 25 4
gpt4 key购买 nike

我使用 AVAudioMixerNode 来更改音频格式。 this入门对我帮助很大。下面的代码给了我我想要的数据。但是我在电话的扬声器上听到了我自己的声音。我该如何预防?

func startAudioEngine()
{
engine = AVAudioEngine()

guard let engine = engine, let input = engine.inputNode else {
// @TODO: error out
return
}

let downMixer = AVAudioMixerNode()
//I think you the engine's I/O nodes are already attached to itself by default, so we attach only the downMixer here:
engine.attach(downMixer)

//You can tap the downMixer to intercept the audio and do something with it:
downMixer.installTap(onBus: 0, bufferSize: 2048, format: downMixer.outputFormat(forBus: 0), block: //originally 1024
{ (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in

//i get audio data here
}
)

//let's get the input audio format right as it is
let format = input.inputFormat(forBus: 0)
//I initialize a 16KHz format I need:
let format16KHzMono = AVAudioFormat.init(commonFormat: AVAudioCommonFormat.pcmFormatInt16, sampleRate: 11025.0, channels: 1, interleaved: true)

//connect the nodes inside the engine:
//INPUT NODE --format-> downMixer --16Kformat--> mainMixer
//as you can see I m downsampling the default 44khz we get in the input to the 16Khz I want
engine.connect(input, to: downMixer, format: format)//use default input format
engine.connect(downMixer, to: engine.outputNode, format: format16KHzMono)//use new audio format

engine.prepare()

do {
try engine.start()
} catch {
// @TODO: error out
}
}

最佳答案

您可以通过扬声器听到麦克风录音,因为您的麦克风已连接到 downMixer ,连接到 engine.outputNode .您可能只是将 downMixer 的输出静音如果您不将它与其他输入一起使用:
downMixer.outputVolume = 0.0

关于ios - 将 AVAudioMixerNode 连接到 AVAudioEngine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53959379/

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