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)))) (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! (defn record-student-sound!
[phrase-no] [phrase-no]
@ -1732,10 +1732,10 @@
(try (try
(.then (.getUserMedia (.mediaDevices js/navigator) {:audio true}) (.then (.getUserMedia (.mediaDevices js/navigator) {:audio true})
(fn [arg] (fn [arg]
(let [media-recorder (MediaRecorder. arg) (let [media-recorder (js/MediaRecorder. arg)
audio-chunks (atom [])] audio-chunks (atom [])]
(.start media-recorder) (.start media-recorder)
(set! media-recorder onerror (set! (.-onerror media-recorder)
(fn [s] (fn [s]
(.log js/console (str "Error while recording sound: " s)))) (.log js/console (str "Error while recording sound: " s))))
(.addEventListener media-recorder "dataavailable" (.addEventListener media-recorder "dataavailable"
@ -1747,7 +1747,7 @@
(js/console.log "data available after MediaRecorder.stop() called.") (js/console.log "data available after MediaRecorder.stop() called.")
(if (> (count @audio-chunks) 0) (if (> (count @audio-chunks) 0)
(do (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 (swap! student-recordings assoc phrase-no
(js/Blob. (clj->js @audio-chunks))) (js/Blob. (clj->js @audio-chunks)))
(enable-play-button! phrase-no)))))))) (enable-play-button! phrase-no))))))))
@ -1801,7 +1801,7 @@
(defn play-student! (defn play-student!
[phrase-no] [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! (defn animate-progress-bar!
[id duration] [id duration]