Skip to content

Instantly share code, notes, and snippets.

@oakmac
Last active April 9, 2021 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oakmac/cc78f71b38d93ab77544d161cbc773df to your computer and use it in GitHub Desktop.
Save oakmac/cc78f71b38d93ab77544d161cbc773df to your computer and use it in GitHub Desktop.
Crunker.js to ClojureScript Interop Example
;; this is a ClojureScript interop example I put together for a student in
;; the Professional ClojureScript course (https://cljs.pro)
(defn fetch-and-merge-files
"Fetches two mp3 files and merges them using the Crunker.js library.
Returns a JavaScript Promise object."
[file1 file2]
(let [js-crunker (new Crunker)]
(-> js-crunker
(.fetchAudio file1 file2)
(.then (fn [js-buffers]
(.mergeAudio js-crunker js-buffers)))
(.then (fn [js-merged]
(.export js-crunker js-merged "audio/mp3")))
(.then (fn [js-output]
(.download js-crunker (oget js-output "blob"))))
(.catch (fn [js-err]
(.error js/console "Something went wrong:" js-err))))))
;; usage:
(-> (fetch-and-merge-files "/voice.mp3" "/background.mp3")
(.then (fn [result-from-download])))
;; do something with result-from-download here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment