diff --git a/client/src/components/AudioOutput.jsx b/client/src/components/AudioOutput.jsx index e32964f..40c51eb 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({ currentAudioMessage }) { + const audioRef = useRef(null); + + useEffect(() => { + if (currentAudioMessage) { + console.log( + "Creating blob with ArrayBuffer of size:", + currentAudioMessage.audio.byteLength + ); + const blob = new Blob([currentAudioMessage.audio], { 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); + }; + } + }, [currentAudioMessage]); + + return ( +