我使用 AVAudioMixerNode 来更改音频格式。这篇文章对我帮助很大。下面的代码给了我我想要的数据。但我在电话扬声器中听到了自己的声音。我该如何预防?
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: …Run Code Online (Sandbox Code Playgroud)