Created
December 3, 2021 10:02
-
-
Save bobbicodes/d9ec35b9f3c015739580c7fc77225772 to your computer and use it in GitHub Desktop.
Use Web Audio API with nbb
This file contains 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
(ns example | |
(:require ["fs" :as fs] | |
["web-audio-api$default" :as wa])) | |
(def ^:dynamic context (wa/AudioContext.)) | |
(set! (.-outStream context) (.-stdout js/process)) | |
(fs/readFile "outfoxing.mp3" | |
(fn [err buffer] | |
(when err (throw err)) | |
(.decodeAudioData context buffer | |
(fn [audioBuffer] | |
(let [bufferNode (.createBufferSource context)] | |
(.connect bufferNode (.-destination context)) | |
(set! (.-buffer bufferNode) audioBuffer) | |
(set! (.-loop bufferNode) true) | |
(.start bufferNode 0)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Play in Linux with aplay:
nbb example.cljs | aplay -f cd