opt: tts play re-render

This commit is contained in:
2023-12-07 01:14:58 +08:00
parent 3f2893d1bf
commit 9a42e2758c
2 changed files with 17 additions and 9 deletions

View File

@@ -130,11 +130,7 @@ export default function Message(props: Props) {
</div> </div>
)} )}
<hr className="mt-2" /> <hr className="mt-2" />
<TTSPlay <TTSPlay chat={chat} />
chat={chat}
chatStore={chatStore}
setChatStore={setChatStore}
/>
<div className="w-full flex justify-between"> <div className="w-full flex justify-between">
<DeleteIcon /> <DeleteIcon />
<button onClick={() => setShowEdit(true)}>🖋</button> <button onClick={() => setShowEdit(true)}>🖋</button>

View File

@@ -1,4 +1,4 @@
import { useState } from "preact/hooks"; import { useMemo, useState } from "preact/hooks";
import { ChatStore, ChatStoreMessage, addTotalCost } from "./app"; import { ChatStore, ChatStoreMessage, addTotalCost } from "./app";
import { Message, getMessageText } from "./chatgpt"; import { Message, getMessageText } from "./chatgpt";
@@ -7,10 +7,22 @@ interface TTSProps {
chat: ChatStoreMessage; chat: ChatStoreMessage;
setChatStore: (cs: ChatStore) => void; setChatStore: (cs: ChatStore) => void;
} }
export function TTSPlay(props: TTSProps) { interface TTSPlayProps {
chat: ChatStoreMessage;
}
export function TTSPlay(props: TTSPlayProps) {
const src = useMemo(() => {
if (props.chat.audio instanceof Blob) { if (props.chat.audio instanceof Blob) {
const url = URL.createObjectURL(props.chat.audio); return URL.createObjectURL(props.chat.audio);
return <audio src={url} controls />; }
return "";
}, [props.chat.audio]);
if (props.chat.hide) {
return <></>;
}
if (props.chat.audio instanceof Blob) {
return <audio className="w-full" src={src} controls />;
} }
return <></>; return <></>;
} }