Reputation: 990
How can I hear on the speaker the same thing that the microphone records but live?
What I want to do is to have my earphones on and hear the same thing but I will just manage the volume.
I know how to record the audio and then play it but I want it to be live, I don't need to save the audio, just hear the same thing at the same time.
Upvotes: 2
Views: 2786
Reputation: 745
I know this question is ancient, but I was recently trying to do this and I found that the easiest way to do this is to use the AVAudioEngine
. Once you instantiate it it has an inputNode
property that represents the mic and an outputNode
property that represents the speakers. You connect the input node to the output node like this:
engine.connect(engine.inputNode, to: engine.outputNode, format: engine.inputNode.inputFormat(forBus: 0))
engine.start()
Upvotes: 5
Reputation: 11
If you just want a ready-made app that does this, download the free Speech Jammer app and disable the audio delay.
Upvotes: 0
Reputation: 70703
You can't get live output, as the iOS audio system buffers audio sample both in and out. But you can often get a latency below 12 milliseconds by using the RemoteIO Audio Unit API after requesting a very short (5 mS) audio buffers in the app's AVAudioSession initialization options.
If you want minimum latency (as close to live as possible) then you will have to understand and use the slightly more complex lower level audio APIs, as the easy high level APIs are slower (usually due to longer buffering).
Upvotes: 0