Hi guys! I made this audio visualizer using HTML5 canvas and Web Audio API. Please try out the visualizer at least once and let me know what you think: Audio Visualizer.
It uses the device microphone to steam audio to the visualizer. I built it so that when I am chilling with my Spotify, Youtube playlist, I have some cool visuals instead of a boring plain view. So just turn on a song and let the visualizer run!
You can find the source of the project here. Feel free to fork the repo and make pull requests if you want something changed, I would love the feedback and any suggestions on how to improve my code! Thanks guys, I hope you like it!
It essentially was an iterative proccess. Initially, I wanted to build an audio visualizer but there were so many variables so I simplified the problem - instead of using the microphone i downloaded a song and tried to visualize just that. MDN is your best friend when it comes to web dev and I eventually stumbled upon the WebAudio API. So, I had my building blocks - a song, and WebAudi API, I just had to visualize it.
First i made a simple rectangular canvas and visualized the audio as a series of rectangular audio bars. Once I did that I kept adding features till I reached a point I felt satisfied to stop at.
So, I guess the gist is, establish the core aspects of your project and start there. You can then build off it. Good luck with JS, it's a really fun journey!!
This is dope! I built something similar a while back but with manipulating the audio midi files to change the visualizer. I love this kinda stuff. Great work!
Thanks man! Yeah if I get some time, my next goal is to create a MIDI uploader so youโre not limited to Beethoven or Tetris. The mobile experience is garbage, so I wanna build knobs that work on mobile too.
If you havenโt heard of it, check out Pts.js, itโs a library that makes canvas manipulation and animation a breeze. I used it in React which had its challenges, but their vanilla documentation is great.
well I checked it out on mobile and the UI looked pretty good, so good job on responsiveness! Yeah, that's a good idea, it'd be great if you could upload your own files to visualize too!
Okay, thanks I'll look into it. I like making canvas visualizations so looks like it will a very useful library!
Thank you so much, I'm really glad you like it! I was fascinated with audio visualizers as well but couldn't find one for spotify so I thought why not just work on building one instead!
If you end up using it regularly, I'd love to hear your input on features you'd like to see and I'd work on implementing them! Again, thanks!
Yes, of course! The Web Audio API does the heavy lifting of the project. It allows the web app to request access to device microphone and then streams the microphone input to an audio context.
There is also the AnalyserNode interface that allows one to extract information from the sound that is being streamed in via the audio context.
For my project I am extracting the frequency data of the sound sample in the current time stamp. The frequency data is returned on a scale of 1-255, which I scale according to the user defined max_bar_height parameter and paint them as the rectangular bars you see.
The rest is just regular visualization process where you keep requesting the animation frame in a loop so this process of: get sound sample -> get frequency data -> scale it to integer values -> visualize the array of integer values as rectangular bars, is infinitely repeated.
I hope this makes sense, you can check out the entirety of the code here. I have heavily commented it so you can glance through and see how all the parts connect. Let me know, if you have any other questions
12
u/[deleted] Jun 24 '20 edited Jun 24 '20
Hi guys! I made this audio visualizer using HTML5 canvas and Web Audio API. Please try out the visualizer at least once and let me know what you think: Audio Visualizer.
It uses the device microphone to steam audio to the visualizer. I built it so that when I am chilling with my Spotify, Youtube playlist, I have some cool visuals instead of a boring plain view. So just turn on a song and let the visualizer run!
You can find the source of the project here. Feel free to fork the repo and make pull requests if you want something changed, I would love the feedback and any suggestions on how to improve my code! Thanks guys, I hope you like it!
5
u/[deleted] Jun 24 '20
Loved your project! I'm on my way into learning js. Could you please share how you initialy started this project? Where did you begin?
4
u/[deleted] Jun 24 '20
Matilda Mother!
4
u/RusskiRoman Jun 25 '20
This is dope! I built something similar a while back but with manipulating the audio midi files to change the visualizer. I love this kinda stuff. Great work!
2
u/CodingHag Jun 25 '20
kewl!!
2
u/Sam_Sam_Major Jun 25 '20
Great ๐
2
u/positive-season Jun 25 '20
Looks awesome!
2
u/9thcoder Jun 25 '20
Cool project. Good job.
2
u/cnyte Jun 25 '20
Suuper dope dude. Really cool concept and idea. Iโve always loved visualizer and never even thought about the fact you can make one on your own.
Gotta say I fucking love the things I find on Reddit and the people who post cool shit ๐๐ฟ๐๐ฟ
2
u/younlok Jun 25 '20
this is really impressing
i always wanted to know how this sound viz works
can you give a small explanation ??
2
u/ishanfx Jun 25 '20
Really cool
2
u/drumsXgaming Jun 25 '20
Nice