fix mic button animation and prompt

This commit is contained in:
2023-08-25 18:38:08 +08:00
parent cdb0c9a1b5
commit b7ae9e0838

View File

@@ -509,7 +509,11 @@ export default function ChatBOX(props: {
{chatStore.whisper_api && {chatStore.whisper_api &&
(chatStore.whisper_key || chatStore.apiKey) && ( (chatStore.whisper_key || chatStore.apiKey) && (
<button <button
className="disabled:line-through disabled:bg-slate-500 rounded m-1 p-1 border-2 bg-cyan-400 hover:bg-cyan-600" className={`disabled:line-through disabled:bg-slate-500 rounded m-1 p-1 border-2 ${
isRecording === "Recording"
? "bg-red-400 hover:bg-red-600"
: "bg-cyan-400 hover:bg-cyan-600"
} ${isRecording !== "Mic" ? "animate-pulse" : ""}`}
disabled={isRecording === "Transcribing"} disabled={isRecording === "Transcribing"}
ref={mediaRef} ref={mediaRef}
onClick={async () => { onClick={async () => {
@@ -521,20 +525,20 @@ export default function ChatBOX(props: {
} }
// build prompt // build prompt
const prompt = ( const prompt =
chatStore.history chatStore.history
.filter(({ hide }) => !hide) .filter(({ hide }) => !hide)
.slice(chatStore.postBeginIndex) .slice(chatStore.postBeginIndex)
.map(({ content }) => content) .map(({ content }) => content)
.join(" ") + .join(" ") +
" " + " " +
inputMsg inputMsg;
).trim();
console.log({ prompt }); console.log({ prompt });
setIsRecording("Recording"); setIsRecording("Recording");
console.log("start recording"); console.log("start recording");
try {
const mediaRecorder = new MediaRecorder( const mediaRecorder = new MediaRecorder(
await navigator.mediaDevices.getUserMedia({ await navigator.mediaDevices.getUserMedia({
audio: true, audio: true,
@@ -589,10 +593,15 @@ export default function ChatBOX(props: {
const { text } = await response.json(); const { text } = await response.json();
setInputMsg(inputMsg + text); setInputMsg(inputMsg ? inputMsg + " " + text : text);
setIsRecording("Mic"); setIsRecording("Mic");
}; };
}); });
} catch (error) {
alert(error);
console.log(error);
setIsRecording("Mic");
}
}} }}
> >
{isRecording} {isRecording}