opt: tts play re-render
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
20
src/tts.tsx
20
src/tts.tsx
@@ -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 <></>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user