|
3 | 3 | import Link from "next/link"; |
4 | 4 | import { useState, useEffect, useRef } from "react"; |
5 | 5 | import { useAuthGuard } from "../../hooks/useAuthGuard"; |
| 6 | + |
| 7 | +interface SpeechRec { |
| 8 | + lang: string; |
| 9 | + interimResults: boolean; |
| 10 | + maxAlternatives: number; |
| 11 | + onresult: ((e: { results: { transcript: string }[][] }) => void) | null; |
| 12 | + onerror: (() => void) | null; |
| 13 | + onend: (() => void) | null; |
| 14 | + start: () => void; |
| 15 | + stop: () => void; |
| 16 | +} |
6 | 17 | import AnimalAvatar from "../../components/AnimalAvatar"; |
7 | 18 | import { db } from "../../lib/db/schema"; |
8 | 19 | import { speakText, checkMicSupport } from "../../lib/audio/ttsHelper"; |
@@ -44,9 +55,7 @@ export default function ChatPage() { |
44 | 55 | const [fallbackMode, setFallbackMode] = useState(false); |
45 | 56 | const [micError, setMicError] = useState<string | null>(null); |
46 | 57 | const messagesEndRef = useRef<HTMLDivElement>(null); |
47 | | - const audioRef = useRef<HTMLAudioElement | null>(null); |
48 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
49 | | - const recognitionRef = useRef<any>(null); |
| 58 | + const recognitionRef = useRef<SpeechRec | null>(null); |
50 | 59 |
|
51 | 60 | /* ---- theme ---- */ |
52 | 61 | useEffect(() => { |
@@ -154,14 +163,12 @@ export default function ChatPage() { |
154 | 163 | (window as unknown as Record<string, unknown>).webkitSpeechRecognition; |
155 | 164 | if (!SR) return; |
156 | 165 |
|
157 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
158 | | - const recognition = new (SR as any)(); |
| 166 | + const recognition = new (SR as new () => SpeechRec)(); |
159 | 167 | recognition.lang = "en-US"; |
160 | 168 | recognition.interimResults = false; |
161 | 169 | recognition.maxAlternatives = 1; |
162 | 170 |
|
163 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
164 | | - recognition.onresult = (event: any) => { |
| 171 | + recognition.onresult = (event: { results: { transcript: string }[][] }) => { |
165 | 172 | const transcript = event.results[0]?.[0]?.transcript; |
166 | 173 | if (transcript) sendMessage(transcript); |
167 | 174 | setIsListening(false); |
|
0 commit comments