我想将此代码用于VoIP服务。
我正在使用网络套接字并与之一起发送:let data = self.toNSData(PCMBuffer: buffer)和播放:let audioBuffer = self.toPCMBuffer(data: data) 在另一台设备上)
我曾经使用过:https://github.com/Lkember/IntercomTest 并对其进行了处理,但是数据量很大。我觉得41100速率对于发送数据来说是一个很大的大小,我想将较低速率的缓冲区减小到8000。
但是我不知道如何在没有错误的情况下降低采样率!
我的失败代码如下:
@IBAction func start(_ sender: Any) {
var engine = AVAudioEngine()
let input = engine.inputNode
let bus = 0
let localAudioPlayer: AVAudioPlayerNode = AVAudioPlayerNode()
let mixer = AVAudioMixerNode()
let fmt = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 8000, channels: 1, interleaved: false)
engine.attach(mixer)
engine.connect(input, to: mixer, format: input.outputFormat(forBus: 0))
mixer.volume = 0
engine.connect(mixer, to: localAudioPlayer, format: fmt)
localAudioPlayer.installTap(onBus: bus, bufferSize: 512, format: fmt) …Run Code Online (Sandbox Code Playgroud)