From 5cc002a1107dd64eee3e3459a2dedf21a255f9e6 Mon Sep 17 00:00:00 2001 From: Andrei Stoica Date: Wed, 28 Feb 2024 11:33:08 -0500 Subject: [PATCH] assistant response is replayable --- speech-speech/frontend/src/App.tsx | 21 +++++++++++---------- speech-speech/frontend/src/components.tsx | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/speech-speech/frontend/src/App.tsx b/speech-speech/frontend/src/App.tsx index 4ddd6b6..27597e7 100644 --- a/speech-speech/frontend/src/App.tsx +++ b/speech-speech/frontend/src/App.tsx @@ -51,14 +51,15 @@ function playRecord() { audio.play(); } -function playMsg(msg: ChatMsg) { - const audio = new Audio( - "/speak?" + - new URLSearchParams({ text: msg.content }), - ); - console.log("loading audio and playing?"); - audio.play(); -} +//function playMsg(msg: ChatMsg) { +// const audio = new Audio( +// "/speak?" + +// new URLSearchParams({ text: msg.content }), +// ); +// console.log("loading audio and playing?"); +// audio.play(); +//} + function App() { const [recordState, setRecordState] = useState(false); const [chatState, setChatState] = useState([{ @@ -99,8 +100,8 @@ function App() { setChatState(( curState: Array, ) => [...curState, res]); - console.log("attempting to play result"); - playMsg(res); + // console.log("attempting to play result"); + //playMsg(res); }); }); } diff --git a/speech-speech/frontend/src/components.tsx b/speech-speech/frontend/src/components.tsx index bc4991f..d1cd6e8 100644 --- a/speech-speech/frontend/src/components.tsx +++ b/speech-speech/frontend/src/components.tsx @@ -6,10 +6,10 @@ import { TbPlayerStop, } from "react-icons/tb"; - export type ChatMsg = { role: string; content: string; + audio: any = null; }; export function Header() { @@ -50,6 +50,18 @@ export function Feed(props: { chat: Array; setChatStateFn: any }) { } export function Msg(props: { msg: ChatMsg }) { + let audio; + if (props.msg.role == "assistant") { + audio = ( +