1
我对从麦克风采集的音频下采样有问题。我使用AVAudioEngine从下面的代码话筒取样品:AVAudioEngine下采样问题
assert(self.engine.inputNode != nil)
let input = self.engine.inputNode!
let audioFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 8000, channels: 1, interleaved: false)
let mixer = AVAudioMixerNode()
engine.attach(mixer)
engine.connect(input, to: mixer, format: input.inputFormat(forBus: 0))
do {
try engine.start()
mixer.installTap(onBus: 0, bufferSize: 1024, format: audioFormat, block: {
(buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
//some code here
})
} catch let error {
print(error.localizedDescription)
}
此代码工作在iPhone 5S伟大的,因为麦克风输入8000Hz的,缓冲器被装满了来自麦克风的数据。
问题是我想能够从iPhone 6s(及更高版本)录制哪些麦克风以16000Hz记录。而什么奇怪的是,如果我连与发动机mainmixernode的mixernode(用下面的代码):
engine.connect(mixer, to: mainMixer, format: audioFormat)
这种实际工作,我也得到了缓冲器具有8000Hz的格式和声音出来完美间苗,唯一的问题是声音也从我不想要的扬声器中发出(如果我不连接它,缓冲区是空的)。
有谁知道如何解决这个问题?
任何帮助,输入或思想非常感激。
在其中定义 “mainMixer”? –
很早以前,我写了这段代码,但我95%确定这是AVAudioEngines主混音器节点。 – nullforlife
如果我使用这段代码,它会给我缓冲区中的所有零。你知道我做错了什么吗?我正在使用具有44100Hz麦克风输入采样率的iPhone 7。 –