Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

remove: voice input feature from chat input (#100)

Generfa43b8d61658
diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsx
index abda34ade..b3d5e1da3 100644
--- a/src/web/src/components/agent-chat/agent-chat-view.tsx
+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx
@@ -43,8 +43,7 @@ import { toast } from "sonner";
import { cn } from "@/lib/utils";
import { Skeleton } from "@/components/ui/skeleton";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
-import { ArrowUp, BedDouble, Box, FileText, Loader2, Mail, MessageSquareQuote, Mic, Paperclip, Square, X } from "lucide-react";
-import { useSpeechRecognition } from "@/hooks/use-speech-recognition";
+import { ArrowUp, BedDouble, Box, FileText, Loader2, Mail, MessageSquareQuote, Paperclip, Square, X } from "lucide-react";
import { useCachedMessages } from "@/hooks/use-cached-messages";
import { useMentionPopup } from "@/hooks/use-mention-popup";
import { MentionPopup } from "@/components/agent-chat/mention-popup";
@@ -384,10 +383,6 @@ export function AgentChatView({
setChannelAgentId(agentId);
}, [agentId, setChannelAgentId]);
- const handleSpeechResult = useCallback((text: string) => {
- setInput((prev) => (prev ? prev + " " + text : text));
- }, []);
- const { listening, supported: speechSupported, toggle: toggleSpeech } = useSpeechRecognition(handleSpeechResult);
const agentArtifacts = useMemo(() => artifacts.filter((a) => a.source === "agent"), [artifacts]);
@@ -2026,28 +2021,6 @@ export function AgentChatView({
</TooltipTrigger>
<TooltipContent side="top">Attach files</TooltipContent>
</Tooltip>
- {speechSupported && (
- <Tooltip>
- <TooltipTrigger render={
- <Button
- variant="ghost"
- size="icon-sm"
- onPointerDown={(e) => e.preventDefault()}
- onClick={toggleSpeech}
- disabled={sending}
- className={cn(
- "rounded-lg transition-colors duration-200",
- listening
- ? "text-red-500 hover:text-red-600 bg-red-500/10"
- : "text-muted-foreground/60 hover:text-foreground"
- )}
- />
- }>
- <Mic className={cn("size-3.5", listening && "animate-pulse")} />
- </TooltipTrigger>
- <TooltipContent side="top">{listening ? "Stop recording" : "Voice input"}</TooltipContent>
- </Tooltip>
- )}
{isTaskActive && !input.trim() && !sending ? (
<Tooltip>
<TooltipTrigger render={
diff --git a/src/web/src/hooks/use-speech-recognition.ts b/src/web/src/hooks/use-speech-recognition.ts
deleted file mode 100644
index c340d39ff..000000000
--- a/src/web/src/hooks/use-speech-recognition.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-"use client";
-
-import { useCallback, useEffect, useRef, useState } from "react";
-
-interface SpeechRecognitionResult {
- readonly [index: number]: { transcript: string; confidence: number };
- readonly length: number;
- readonly isFinal: boolean;
-}
-
-interface SpeechRecognitionResultList {
- readonly [index: number]: SpeechRecognitionResult;
- readonly length: number;
-}
-
-interface SpeechRecognitionEvent {
- readonly results: SpeechRecognitionResultList;
-}
-
-interface SpeechRecognitionInstance {
- lang: string;
- interimResults: boolean;
- continuous: boolean;
- onresult: ((event: SpeechRecognitionEvent) => void) | null;
- onend: (() => void) | null;
- onerror: (() => void) | null;
- start(): void;
- stop(): void;
- abort(): void;
-}
-
-function getSR(): (new () => SpeechRecognitionInstance) | null {
- if (typeof window === "undefined") return null;
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- const w = window as any;
- return w.SpeechRecognition ?? w.webkitSpeechRecognition ?? null;
-}
-
-export function useSpeechRecognition(onResult: (text: string) => void) {
- const [listening, setListening] = useState(false);
- const [supported, setSupported] = useState(false);
- const recognitionRef = useRef<SpeechRecognitionInstance | null>(null);
-
- useEffect(() => {
- setSupported(!!getSR());
- }, []);
-
- const start = useCallback(() => {
- const SR = getSR();
- if (!SR) return;
-
- const recognition = new SR();
- recognition.lang = navigator.language || "zh-CN";
- recognition.interimResults = false;
- recognition.continuous = false;
-
- recognition.onresult = (event) => {
- const results = event.results;
- let transcript = "";
- for (let i = 0; i < results.length; i++) {
- transcript += results[i][0].transcript;
- }
- if (transcript) onResult(transcript);
- };
-
- recognition.onend = () => {
- setListening(false);
- recognitionRef.current = null;
- };
-
- recognition.onerror = () => {
- setListening(false);
- recognitionRef.current = null;
- };
-
- recognitionRef.current = recognition;
- recognition.start();
- setListening(true);
- }, [onResult]);
-
- const stop = useCallback(() => {
- recognitionRef.current?.stop();
- }, []);
-
- const toggle = useCallback(() => {
- if (listening) {
- stop();
- } else {
- start();
- }
- }, [listening, start, stop]);
-
- useEffect(() => {
- return () => {
- recognitionRef.current?.abort();
- };
- }, []);
-
- return { listening, supported, toggle };
-}