← All examples

04 Microphone + Canvas · Intermediate

Give your voice a shape.

Switch the source from a track to your microphone and draw the waveform of your voice.

bass
0.00
mid
0.00
high
0.00
Analysed in your browser. Not recorded or sent anywhere.

What you’ll learn

Request microphone access from a click, read time-domain data and stop the stream when finished.

The complete setup, with playback and cleanup →

Download the working example component ↓

The key idea · excerpt
// Inside a button click handler:
await audio.enableMic();

// Inside your animation loop:
const { waveform } = audio.snapshot('mic');

// When the user turns the microphone off:
audio.disableMic();

Music: I dunno by grapes · Drive by AlexBeroza · Parametaphoriquement by gmz · nightWalk by airtone. From ccMixter, under CC BY 3.0.