Skip to content

Instantly share code, notes, and snippets.

@okiwan
Last active April 19, 2019 17:09
Show Gist options
  • Select an option

  • Save okiwan/21df74f5bd6a71d0b1b50359290f2041 to your computer and use it in GitHub Desktop.

Select an option

Save okiwan/21df74f5bd6a71d0b1b50359290f2041 to your computer and use it in GitHub Desktop.
Use audio analyzer to create an equalizer on your browser
/**
* Originally created by @jake_albaugh (Twitter)
* UTF8 characters starting from "\u2581"
*/
const l = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
const x = new AudioContext();
const a = x.createAnalyser();
a.fftSize = 32;
const d = new Uint8Array(16);
navigator.mediaDevices.getUserMedia({ audio: true }).then(s => {
x.createMediaStreamSource(s).connect(a);
z();
});
function z() {
setTimeout(z, 40);
a.getByteFrequencyData(d);
const data = Array.from(d);
const s = data.map(v => l[Math.floor((v / 255) * 8)]);
window.location.hash = document.title = s.join("");
document.title = s.join("");
const outStr = s.join("");
window.history.replaceState("", outStr, outStr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment