assistant response is replayable

This commit is contained in:
Andrei Stoica 2024-02-28 11:33:08 -05:00
parent 7562778f18
commit 5cc002a110
2 changed files with 25 additions and 11 deletions

View File

@ -51,14 +51,15 @@ function playRecord() {
audio.play(); audio.play();
} }
function playMsg(msg: ChatMsg) { //function playMsg(msg: ChatMsg) {
const audio = new Audio( // const audio = new Audio(
"/speak?" + // "/speak?" +
new URLSearchParams({ text: msg.content }), // new URLSearchParams({ text: msg.content }),
); // );
console.log("loading audio and playing?"); // console.log("loading audio and playing?");
audio.play(); // audio.play();
} //}
function App() { function App() {
const [recordState, setRecordState] = useState(false); const [recordState, setRecordState] = useState(false);
const [chatState, setChatState] = useState([{ const [chatState, setChatState] = useState([{
@ -99,8 +100,8 @@ function App() {
setChatState(( setChatState((
curState: Array<ChatMsg>, curState: Array<ChatMsg>,
) => [...curState, res]); ) => [...curState, res]);
console.log("attempting to play result"); // console.log("attempting to play result");
playMsg(res); //playMsg(res);
}); });
}); });
} }

View File

@ -6,10 +6,10 @@ import {
TbPlayerStop, TbPlayerStop,
} from "react-icons/tb"; } from "react-icons/tb";
export type ChatMsg = { export type ChatMsg = {
role: string; role: string;
content: string; content: string;
audio: any = null;
}; };
export function Header() { export function Header() {
@ -50,6 +50,18 @@ export function Feed(props: { chat: Array<ChatMsg>; setChatStateFn: any }) {
} }
export function Msg(props: { msg: ChatMsg }) { export function Msg(props: { msg: ChatMsg }) {
let audio;
if (props.msg.role == "assistant") {
audio = (
<audio
controls
autoPlay
src={"/speak?" + new URLSearchParams({ text: props.msg.content })}
/>
);
} else if (props.msg.audio){
<div />;
}
return ( return (
<div className="Messege text-lg"> <div className="Messege text-lg">
<span className="font-bold"> <span className="font-bold">
@ -59,6 +71,7 @@ export function Msg(props: { msg: ChatMsg }) {
<span className="ml-8"> <span className="ml-8">
{props.msg.content} {props.msg.content}
</span> </span>
{audio}
</div> </div>
); );
} }