Audio visualizer from mic

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

https://mdn.github.io/voice-change-o-matic/

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