brkr brkr - 8 months ago 119
Swift Question

Create Voice Frequency Graph when user record audio?

Im building a voice recording app and I would like to show a voice frequency graph similar to "Voice Memo" app on iPhone.

Im not sure exactly where to start build this.. could anyone give me some areas to look into and how to structure it? Ill then go learn all the areas and build it!

Thank you


The top chart measures Intensity vs. Time. This is the most intuitive representation of a sound because a louder voice would show up as a larger spike. Intensity is measured in Percentage of Full-Scale (%FS) units where 100% corresponds to the loudest recordable sound by the device. When a person speaks into a microphone, a voltage fluctuates up and down over time. This is what this graph represents.

The bottom chart is a Power Spectral Density. It shows where there is most power in the signal. For example, a deep loud voice would appear as a maximum at the lower end of the x-axis, corresponding to the low frequencies a deep voice contains. Power is measured in dB (a logarithmic unit) at different frequencies.

After a bit of Googling and testing, I think AVFoundation doesn't provide access to the audio data in real-time, it's a high-level API primarily useful for recording to a file and playing back. The lower-level Audio Queue Services API seems to be the way to go (although I'm sure there are libraries out there that simplify its complex API).

Audio Queue Services Programming Guide:

DSP in Swift: