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>
)}
<hr className="mt-2" />
<TTSPlay
chat={chat}
chatStore={chatStore}
setChatStore={setChatStore}
/>
<TTSPlay chat={chat} />
<div className="w-full flex justify-between">
<DeleteIcon />
<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 { Message, getMessageText } from "./chatgpt";
@@ -7,10 +7,22 @@ interface TTSProps {
chat: ChatStoreMessage;
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) {
return URL.createObjectURL(props.chat.audio);
}
return "";
}, [props.chat.audio]);
if (props.chat.hide) {
return <></>;
}
if (props.chat.audio instanceof Blob) {
const url = URL.createObjectURL(props.chat.audio);
return <audio src={url} controls />;
return <audio className="w-full" src={src} controls />;
}
return <></>;
}