Last active
April 9, 2021 02:06
-
-
Save oakmac/cc78f71b38d93ab77544d161cbc773df to your computer and use it in GitHub Desktop.
Crunker.js to ClojureScript Interop Example
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
;; 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