θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
03a658e
Added ctrl + enter hotkeys to init speach to text
Rrojaski Jun 26, 2024
f5280b7
Ran linter
Rrojaski Jun 27, 2024
fa10081
Merge branch 'master' into 1603-speach-to-text
timothycarambat Jun 28, 2024
49f0981
Fixed speech transcript from being submitted twice when the user clic…
Rrojaski Jul 1, 2024
bf059e4
Merge branch '1603-speach-to-text' of https://github.com/Rrojaski/any…
Rrojaski Jul 1, 2024
63bdd1b
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 2, 2024
b9c1fb5
Added pulse animation to mic
Rrojaski Jul 2, 2024
bed5ac8
Fixed prompt double-send when clicking the send button or ending the …
Rrojaski Jul 3, 2024
bb79162
Fixed comment grammar
Rrojaski Jul 3, 2024
ff5dceb
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 8, 2024
df4fce4
Merge branch 'Mintplex-Labs:master' into 1603-speach-to-text
Rrojaski Jul 9, 2024
022e598
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 11, 2024
85090e3
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 12, 2024
1506829
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 15, 2024
b2f87a8
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 16, 2024
fda352b
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 17, 2024
c9db12f
Merge branch 'master' into 1603-speach-to-text
timothycarambat Jul 23, 2024
33f101a
Merge branch 'master' into 1603-speach-to-text
Rrojaski Jul 31, 2024
78fd73e
Merge branch '1603-speach-to-text' of https://github.com/Rrojaski/any…
Rrojaski Jul 31, 2024
7c9d2c3
Update mic hotkeys
Rrojaski Jul 31, 2024
921ea33
Merge branch 'master' into 1603-speach-to-text
timothycarambat Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useEffect } from "react";
import { useEffect, useCallback } from "react";
import { Microphone } from "@phosphor-icons/react";
import { Tooltip } from "react-tooltip";
import _regeneratorRuntime from "regenerator-runtime";
import SpeechRecognition, {
useSpeechRecognition,
} from "react-speech-recognition";
import { PROMPT_INPUT_EVENT } from "../../PromptInput";

let timeout;
const SILENCE_INTERVAL = 3_200; // wait in seconds of silence before closing.
Expand Down Expand Up @@ -45,15 +46,49 @@ export default function SpeechToText({ sendCommand }) {
clearTimeout(timeout);
}

const handleKeyPress = useCallback(
(event) => {
if (event.ctrlKey && event.keyCode === 77) {
if (listening) {
endTTSSession();
} else {
startSTTSession();
}
}
},
[listening, endTTSSession, startSTTSession]
);

function handlePromptUpdate(e) {
if (!e?.detail && timeout) {
endTTSSession();
clearTimeout(timeout);
}
}

useEffect(() => {
document.addEventListener("keydown", handleKeyPress);
return () => {
document.removeEventListener("keydown", handleKeyPress);
};
}, [handleKeyPress]);

useEffect(() => {
if (!!window)
window.addEventListener(PROMPT_INPUT_EVENT, handlePromptUpdate);
return () =>
window?.removeEventListener(PROMPT_INPUT_EVENT, handlePromptUpdate);
}, []);

useEffect(() => {
if (transcript?.length > 0) {
if (transcript?.length > 0 && listening) {
sendCommand(transcript, false);
clearTimeout(timeout);
timeout = setTimeout(() => {
endTTSSession();
}, SILENCE_INTERVAL);
}
}, [transcript]);
}, [transcript, listening]);

if (!browserSupportsSpeechRecognition) return null;
return (
Expand All @@ -69,7 +104,9 @@ export default function SpeechToText({ sendCommand }) {
>
<Microphone
weight="fill"
className="w-6 h-6 pointer-events-none text-white"
className={`w-6 h-6 pointer-events-none text-white overflow-hidden rounded-full ${
listening ? "animate-pulse" : ""
}`}
/>
<Tooltip
id="tooltip-text-size-btn"
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/components/WorkspaceChat/ChatContainer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import handleSocketResponse, {
AGENT_SESSION_START,
} from "@/utils/chat/agent";
import DnDFileUploaderWrapper from "./DnDWrapper";
import SpeechRecognition, {
useSpeechRecognition,
} from "react-speech-recognition";

export default function ChatContainer({ workspace, knownHistory = [] }) {
const { threadSlug = null } = useParams();
Expand All @@ -29,6 +32,10 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
setMessage(event.target.value);
};

const { listening, resetTranscript } = useSpeechRecognition({
clearTranscriptOnListen: true,
});

// Emit an update to the state of the prompt input without directly
// passing a prop in so that it does not re-render constantly.
function setMessageEmit(messageContent = "") {
Expand Down Expand Up @@ -57,11 +64,20 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
},
];

if (listening) {
// Stop the mic if the send button is clicked
endTTSSession();
}
setChatHistory(prevChatHistory);
setMessageEmit("");
setLoadingResponse(true);
};

function endTTSSession() {
SpeechRecognition.stopListening();
resetTranscript();
}

const regenerateAssistantMessage = (chatId) => {
const updatedHistory = chatHistory.slice(0, -1);
const lastUserMessage = updatedHistory.slice(-1)[0];
Expand Down
23 changes: 22 additions & 1 deletion frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export default {
]
},
animation: {
sweep: "sweep 0.5s ease-in-out"
sweep: "sweep 0.5s ease-in-out",
pulse: "pulse 1.5s infinite"
},
keyframes: {
sweep: {
Expand All @@ -100,6 +101,26 @@ export default {
fadeOut: {
"0%": { opacity: 1 },
"100%": { opacity: 0 }
},
pulse: {
"0%": {
opacity: 1,
transform: "scale(1)",
boxShadow: "0 0 0 rgba(255, 255, 255, 0.0)",
backgroundColor: "rgba(255, 255, 255, 0.0)"
},
"50%": {
opacity: 1,
transform: "scale(1.1)",
boxShadow: "0 0 15px rgba(255, 255, 255, 0.2)",
backgroundColor: "rgba(255, 255, 255, 0.1)"
},
"100%": {
opacity: 1,
transform: "scale(1)",
boxShadow: "0 0 0 rgba(255, 255, 255, 0.0)",
backgroundColor: "rgba(255, 255, 255, 0.0)"
}
}
}
}
Expand Down