1

我有以下代码可以尝试使用采样率 8000 我如何降低采样率?我找到了解决方案,但它对我不起作用!

这就是解决方案....

    assert(audioEngine.inputNode != nil)
    let input = audioEngine.inputNode!

    let audioFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 8000, channels: 1, interleaved: false)
    let mixer = AVAudioMixerNode()
   // var mainMixerNode: AVAudioMixerNode { get }
    audioEngine.attach(mixer)
    audioEngine.connect(input, to: mixer, format: input.inputFormat(forBus: 0))
    mixer.volume = 0

    audioEngine.connect(mixer, to: audioEngine.mainMixerNode, format: audioFormat)

    do {
        try audioEngine.start()

        mixer.installTap(onBus: 0, bufferSize: 1024, format: audioFormat, block: {
            (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
            //some code here
            print(buffer)

            let firstChannel = buffer.floatChannelData?[0]

            //UnsafeMutablePointer
            let arr = Array(UnsafeBufferPointer(start: firstChannel, count: Int(buffer.frameLength)))

            self.array.append(contentsOf: arr)

            print(self.array)


        })

    } catch let error {
        print(error.localizedDescription)
    }

但是在我的 self.array 中总是 null = 0

我做错了什么?

4

0 回答 0