This is a crude but working version that I want to hang onto while the more

sophisticated version it still broken.
This commit is contained in:
Simon Brooke 2025-09-27 10:46:48 +01:00
parent ca5dd2d21b
commit f2dd660889

View file

@ -1723,7 +1723,7 @@
(def student-recordings (atom (apply vector (repeat (count data) nil))))
(defn enable-play-button [phrase-no])
(defn enable-play-button! [phrase-no])
(defn record-student-sound!
[phrase-no]
@ -1732,10 +1732,10 @@
(try
(.then (.getUserMedia (.mediaDevices js/navigator) {:audio true})
(fn [arg]
(let [media-recorder (MediaRecorder. arg)
(let [media-recorder (js/MediaRecorder. arg)
audio-chunks (atom [])]
(.start media-recorder)
(set! media-recorder onerror
(set! (.-onerror media-recorder)
(fn [s]
(.log js/console (str "Error while recording sound: " s))))
(.addEventListener media-recorder "dataavailable"
@ -1747,7 +1747,7 @@
(js/console.log "data available after MediaRecorder.stop() called.")
(if (> (count @audio-chunks) 0)
(do
;; Store the blob in the student-sounds data structure
;; Store the blob in the student-recordings data structure
(swap! student-recordings assoc phrase-no
(js/Blob. (clj->js @audio-chunks)))
(enable-play-button! phrase-no))))))))
@ -1801,7 +1801,7 @@
(defn play-student!
[phrase-no]
(.play (js/Audio. (.createObjectURL js/URL (@student-sounds phrase-no)))))
(.play (js/Audio. (.createObjectURL js/URL (@student-recordings phrase-no)))))
(defn animate-progress-bar!
[id duration]