在过去的几周里,我一直试图从许多不同的例子中拼凑出一个解决方案,这将使我能够:
我见过的几乎所有示例都涉及将音频编码到文件中,我这样做是为了测试,但不是我需要的。我需要取一个数据包,编码并传输它
MicrophoneService这基本上设置了 aAVAudioEngine并将a附加AVAudioMixerNode到它,这对音频进行了下采样。
然后将结果放入阻塞队列 ( AudioEncoderQueue) 以便编码服务可以对缓冲区进行编码
import Foundation
import AVFoundation
// Base on /sf/ask/2771681111/
// https://github.com/onmyway133/notes/issues/367
class MicrophoneService {
let audioEngine = AVAudioEngine()
init() {
do {
try AVAudioSession.sharedInstance().setPreferredSampleRate(16000)
} catch let error {
print(error)
}
let engineInputNode = audioEngine.inputNode
let bus = 0
let engineInputNodeFormat = engineInputNode.outputFormat(forBus: bus)
//engineInputNode.installTap(onBus: bus, bufferSize: 1024, format: engineInputNodeFormat) { (buffer, time) in
// AudioEncoderQueue.shared.put(buffer)
//}
let mixer = …Run Code Online (Sandbox Code Playgroud) 我试图在iOS中将AAC音频解码为PCM音频,最好的方法是什么?任何示例代码都非常有用......有没有简单的API来做这个...?