From 63ef0d7e0ccefe26b2c2e085a35ae5fb4d2e5062 Mon Sep 17 00:00:00 2001 From: albin-karlsson <55614148+albin-karlsson@users.noreply.github.com> Date: Sat, 20 Apr 2024 12:07:38 +0200 Subject: [PATCH] Add audio --- client/src/components/AudioOutput.jsx | 37 ++++++++++++++++++-- client/src/components/Contact.jsx | 15 ++++++-- client/src/components/Council.jsx | 22 ++++++++---- client/src/components/Output.jsx | 49 +++++++++++++++------------ 4 files changed, 88 insertions(+), 35 deletions(-) diff --git a/client/src/components/AudioOutput.jsx b/client/src/components/AudioOutput.jsx index e32964f..50141a9 100644 --- a/client/src/components/AudioOutput.jsx +++ b/client/src/components/AudioOutput.jsx @@ -1,7 +1,38 @@ -import React from "react"; +// In the AudioOutput component +import React, { useEffect, useRef } from "react"; -function AudioOutput() { - return <>; +function AudioOutput({ currentAudioBuffer }) { + const audioRef = useRef(null); + + useEffect(() => { + if (currentAudioBuffer) { + console.log( + "Creating blob with ArrayBuffer of size:", + currentAudioBuffer.byteLength + ); + const blob = new Blob([currentAudioBuffer], { type: "audio/mp3" }); + const url = URL.createObjectURL(blob); + console.log("Blob URL:", url); // Check the generated URL + audioRef.current.src = url; + audioRef.current + .play() + .catch((err) => console.error("Error playing audio:", err)); + + return () => { + console.log("Revoking URL:", url); + URL.revokeObjectURL(url); + }; + } + }, [currentAudioBuffer]); + + return ( +