Audio visualizer from mic

Im trying to create an app which uses the mic to receive audio and visualize it into a waveform or into something like this

It needs to be realtime hence using mic, if not mic how can we integrate it to songs playing in spotify or something?
Any lead would be appreciated