Last active
April 19, 2019 17:09
-
-
Save okiwan/21df74f5bd6a71d0b1b50359290f2041 to your computer and use it in GitHub Desktop.
Use audio analyzer to create an equalizer on your browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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