r/learnjavascript • • Jun 24 '20

I made a highly customizable Audio Visualizer!

448 Upvotes

39 comments sorted by

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!

2

u/Alwayswatchout Jun 24 '20

Tried to use while listening to something on YouTube. Dont seem to work. What I am doing wrong :s

3

u/[deleted] Jun 24 '20

Hmm, strange.If you're using chrome, you got to click anywhere on the page first, maybe that?

Chrome requires some initial user gesture to fire audioContext. Or maybe your browser's blocking mic access to the page? let me know if it works!

4

u/Alwayswatchout Jun 24 '20

No mic assess worked.

Edit: access not assess ffs

Mind you im using it on my phone so don't know if that is why....

5

u/[deleted] Jun 24 '20

oh yeah I haven't optimized it to work on mobile yet, sorry about that. should've mentioned that, but i plan on adding that in the next iteration.

Meanwhile, if you get the chance please try it out on a desktop browser and let me know, I'd love to get some feedback on it!

2

u/Jorgepasco1 Jun 25 '20

Maybe you could include a Tap to start button for Chrome?

1

u/[deleted] Jun 25 '20

yes that is a good idea, I will implement that! Do you have any other features in mind I could work on?

2

u/jeremiahfernandez0 Jun 24 '20

awesome! is it possible to filter the bars by frequency?

2

u/[deleted] Jun 25 '20

ooh not yet, I hadn't thought of it, but that'll be an interesting feature!

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?

18

u/[deleted] Jun 24 '20

yeah, of course, I'm glad 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!!

4

u/[deleted] Jun 24 '20

Matilda Mother!

3

u/[deleted] Jun 24 '20

An underrated album!

2

u/[deleted] Jun 24 '20

Hell yeah it is

0

u/[deleted] Jun 24 '20

[deleted]

1

u/[deleted] Jun 25 '20

thank you, appreciate it!

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!

3

u/[deleted] Jun 25 '20

Wow, I just checked it out and that's really well built! I love the animations you've made for your visualization.

Do you have any plans to make updates in the future? Anyway, great job man, starred it on github!

4

u/RusskiRoman Jun 25 '20

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.

4

u/[deleted] Jun 25 '20

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!

2

u/CodingHag Jun 25 '20

kewl!!

1

u/[deleted] Jun 25 '20

thanks!

2

u/Sam_Sam_Major Jun 25 '20

Great ๐Ÿ‘

1

u/[deleted] Jun 25 '20

thanks, appreciate it!

2

u/positive-season Jun 25 '20

Looks awesome!

1

u/[deleted] Jun 25 '20

thank you, I'm glad you like it!

2

u/9thcoder Jun 25 '20

Cool project. Good job.

1

u/[deleted] Jun 25 '20

Thank you!

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 ๐Ÿ™Œ๐Ÿฟ๐Ÿ™Œ๐Ÿฟ

1

u/[deleted] Jun 25 '20

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!

2

u/cnyte Jun 25 '20

For sure man, will do.

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 ??

1

u/[deleted] Jun 25 '20

Thank you, I'm glad you like it!

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

2

u/younlok Jun 25 '20

thank you so much that was well explained thank you

2

u/ishanfx Jun 25 '20

Really cool

1

u/[deleted] Jun 25 '20

thanks!

1

u/Diligent_Scallion_24 Jan 22 '24

The visualizer seems to be inactive; or there are no clear operating instructions.

2

u/drumsXgaming Jun 25 '20

Nice

0

u/nice-scores Jun 25 '20

๐“ท๐“ฒ๐“ฌ๐“ฎ โ˜œ(๏พŸใƒฎ๏พŸโ˜œ)

Nice Leaderboard

1. u/RepliesNice at 10096 nices

2. u/Manan175 at 7108 nices

3. u/DOCTORDICK8 at 7101 nices

...

245371. u/drumsXgaming at 1 nice


I AM A BOT | REPLY !IGNORE AND I WILL STOP REPLYING TO YOUR COMMENTS