从麦克风到耳机的实时音频流(IOS)

时间:2019-05-14 20:09:28

标签: swift avfoundation

我需要将音频从iPhone的麦克风传输到连接的耳机。

我尝试了以下代码:

var audioEngine = AVAudioEngine()
    var inputNode: AVAudioInputNode!

    override func viewDidLoad() {
        super.viewDidLoad()

        let inputFormat = audioEngine.inputNode.inputFormat(forBus: 0)

        audioEngine.connect(audioEngine.inputNode, to: audioEngine.outputNode, format: inputFormat)

        audioEngine.prepare()
        try! audioEngine.start()
    }

0 个答案:

没有答案