The Web Audio API
It starts with the Web Audio API. This is the backbone of all the sounds. It’s what lets you generate audio programmatically in the browser without needing audio files. It’s been available across browsers since April 2021 and works on everything modern. The docs for it are extremely dense and kind of a bore to read through unless you’re someone who understands sound completely (not me). So what I did, is funnel it into Cursor and started conversing with it.Prompting Cursor
The first few prompts were actually quite good. I was able to get a click sound from scratch by just describing what I wanted. However, I wanted to build a library of sounds, so I needed to be able to describe the sounds I wanted and have Cursor be able to generate them from scratch. To do this, I like to understand what makes a sound good or bad. This is a process of trial and error, but it’s a process that can be automated with AI. Cursor told me that I needed to understand the math behind the sounds I wanted to create. Mainly that some sounds required things like “filtered noise” or “oscillators” or “envelopes”. I had no idea what “filtered noise” meant, so I asked. Basically,noise is just random values. By itself it sounds harsh and unnatural, but when used right is rather tasteful.
I asked Cursor to show me different filter types on the same noise. lowpass made it muffled. highpass made it thin and harsh. bandpass in the right range made it sound like a click. Once I had something that resembled a click, it was wrong in ways I could describe but not fix. I wanted a click sound that was short and percussive, but it was either too long or too short. It was either too harsh or too muffled. It was either too high or too low.
Finally, when I asked it to “fade naturally,” it introduced me to envelopes. Envelopes are how sounds change volume over time. It explained that real sounds don’t just stop, they decay. And they decay exponentially, not linearly.
Basically you can split it into two parts: the
attack and the decay. Turning up the attack makes the sound louder and faster, while turning up the decay makes the sound quieter and slower.The Sound Library
Here’s an example of what the implementation looks like. This is a complete sound library built using the Web Audio API:Key Concepts
Filtered Noise: Random audio data passed through filters to create percussive sounds like clicks and ticks. Oscillators: Tone generators that create sine, triangle, sawtooth, and square waves for melodic sounds. Envelopes: Control how volume changes over time using attack (fade in) and decay (fade out) parameters. Filters: Shape the frequency content of sounds:lowpass- Keeps low frequencies, removes highs (muffled)highpass- Keeps high frequencies, removes lows (thin)bandpass- Keeps a specific frequency range (focused)
Looking Back
I went into this knowing nothing about audio engineering and came out with a library of sounds. Sounds I understand and can tweak instead of random files I downloaded. The process was collaborative. I provided taste and AI provided implementation. Neither of us could have done it alone. What I learned is that sometimes not knowing the technicalities is actually a good thing. Using Cursor as a translator helped me turn feelings into logic.When trying to create something new, it’s easy to get stuck in your own head and think you need to know everything about the thing you’re trying to create. This is not the case anymore.