How to work with audio in Javascript

Hey guys! I’m learning about javascript now and I would like to know if there is a way to embed audio like we do with images and videos. I have this project: https://codepen.io/danielasegadilha/pen/WNYOzXo

and I would like to make the noise of a drop every time the scale is equal to 0.25. To do it on my computer I could download some audio from youtube and cut it, but I don’t know how to access it in codepen. I would like to only play tha audio for 1 second, just the time it really takes to make a drop noise. If it is not possible to generate the embed audio, is it possible to use the URL of some audio from youtube and specify from which minute I want to play it, and for how long, in javascript? Thank you!

You can take a look at this project JS Drum Kit It’s a drum kit and it plays a small sound clip when you click on the drum element

MDN: Web Audio API

Codepen doesn’t allow file uploads for free accounts. Use a site like StackBlitz/CodeSandbox/Replit instead.

Otherwise, you have to put the audio files on some other host so you can use them on Codepen.

Here’s a pen I created: https://codepen.io/jim-kernicky/pen/JjWOZWx

Howler.js is a popular library to ease working with audio files.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.