added SpeechRecognition declarations and missing type packages

This commit is contained in:
samit 2026-02-21 01:00:08 -08:00
commit 3fb9b4c056
2 changed files with 49 additions and 2 deletions

View file

@ -38,7 +38,6 @@ function fileToBase64DataURL(file: File): Promise<string> {
}
function useDictation(
textareaRef: React.RefObject<HTMLTextAreaElement | null>,
setText: (value: string | ((prev: string) => string)) => void,
) {
const [isDictating, setIsDictating] = useState(false);
@ -188,7 +187,6 @@ export function SharedComposer({
const fileInputRef = useRef<HTMLInputElement>(null);
const { isDictating, start: startDictation, stop: stopDictation, supported: dictationSupported } = useDictation(
textareaRef,
setText,
);

View file

@ -0,0 +1,49 @@
/**
* Minimal Web Speech API (Speech Recognition) types for browsers that support it.
* Full types: @types/dom-speech-recognition
*/
interface SpeechRecognitionResultList {
readonly length: number;
item(index: number): SpeechRecognitionResult;
[index: number]: SpeechRecognitionResult;
}
interface SpeechRecognitionResult {
readonly length: number;
readonly isFinal: boolean;
item(index: number): SpeechRecognitionAlternative;
[index: number]: SpeechRecognitionAlternative;
}
interface SpeechRecognitionAlternative {
readonly transcript: string;
readonly confidence: number;
}
interface SpeechRecognitionEvent extends Event {
readonly resultIndex: number;
readonly results: SpeechRecognitionResultList;
}
interface SpeechRecognition extends EventTarget {
continuous: boolean;
interimResults: boolean;
lang: string;
onresult: ((event: SpeechRecognitionEvent) => void) | null;
onerror: ((event: Event) => void) | null;
onend: (() => void) | null;
start(): void;
stop(): void;
abort(): void;
}
interface SpeechRecognitionConstructor {
new (): SpeechRecognition;
}
interface Window {
SpeechRecognition?: SpeechRecognitionConstructor;
webkitSpeechRecognition?: SpeechRecognitionConstructor;
}
declare var SpeechRecognition: SpeechRecognitionConstructor | undefined;