Rahul Ahuja
Rahul Ahuja

Reputation: 765

Real time audio recording in Swift

I am building an application which needs to do real time audio recording. I am using Swift for the project - so unable to use Novocaine library (as it has some Obj-C++ code).

What I need is get small chunks of the audio recording (real-time) which I can process or send to my websocket. Is there a Swift library that I can use to achieve this?

In addition to getting the live audio from the microphone, I also need to show a real time waveform.

Let me know.

Upvotes: 4

Views: 5255

Answers (1)

Valerii Lider
Valerii Lider

Reputation: 1814

You do not need any of 3-rd party tools for getting audio from mic. It can be set up easily using AVAudioEngine. However, for minimising network traffic I suggest to use lame for compressing raw PCM audio stream into mp3.

Here you can find project with minimal functionality for getting mic input and compressing into mp3. In this example project mp3 stores into Documents folder, so you can try and listen to make sure it works.

From this point you can take mp3 buffer and send via socket. You can also play with lame settings to change quality, etc.

There is another branch called no-lame where same functionality implemented without lame encoding. Look here

Upvotes: 5

Related Questions