diff --git a/app/src/components/input.tsx b/app/src/components/input.tsx index 0a7352c..2e440b6 100644 --- a/app/src/components/input.tsx +++ b/app/src/components/input.tsx @@ -104,7 +104,7 @@ export default function MessageInput(props: MessageInputProps) { } }, [context, message, dispatch]); - const onSpeechStart = () => { + const onSpeechStart = useCallback(() => { if (!recording) { setRecording(true); @@ -141,27 +141,30 @@ export default function MessageInput(props: MessageInputProps) { data.append('file', file); data.append('model', 'whisper-1') - const response = await fetch("https://api.openai.com/v1/audio/transcriptions", { - method: "POST", - headers: { - 'Authorization': `Bearer ${openAIApiKey}`, - }, - body: data, - }); + try { + const response = await fetch("https://api.openai.com/v1/audio/transcriptions", { + method: "POST", + headers: { + 'Authorization': `Bearer ${openAIApiKey}`, + }, + body: data, + }); - const json = await response.json() + const json = await response.json() - if (json.text) { - dispatch(setMessage(json.text)); + if (json.text) { + dispatch(setMessage(json.text)); + } + } catch (e) { + console.log(e) } }).catch((e: any) => console.error(e)); } else { speechRecognition.stop(); - } } - } + }, [recording, message, dispatch]); const onKeyDown = useCallback((e: React.KeyboardEvent) => { @@ -192,14 +195,14 @@ export default function MessageInput(props: MessageInputProps) { )} {!context.generating && ( <> - - - + + + )} diff --git a/app/src/components/settings/user.tsx b/app/src/components/settings/user.tsx index fc2370e..6b6d130 100644 --- a/app/src/components/settings/user.tsx +++ b/app/src/components/settings/user.tsx @@ -1,6 +1,6 @@ import SettingsTab from "./tab"; import SettingsOption from "./option"; -import { TextInput } from "@mantine/core"; +import { Checkbox, TextInput } from "@mantine/core"; import { useCallback, useMemo } from "react"; import { useAppDispatch, useAppSelector } from "../../store"; import { selectOpenAIApiKey, setOpenAIApiKeyFromEvent, selectUseOpenAIWhisper, setUseOpenAIWhisperFromEvent } from "../../store/api-keys"; @@ -30,9 +30,13 @@ export default function UserOptionsTab(props: any) {

-

- Use the OpenAI Whisper API for speech recognition. -

+ + +

diff --git a/app/src/store/api-keys.ts b/app/src/store/api-keys.ts index 3a53cf7..eced56c 100644 --- a/app/src/store/api-keys.ts +++ b/app/src/store/api-keys.ts @@ -3,12 +3,12 @@ import type { RootState } from '.'; const initialState: { openAIApiKey?: string | null | undefined; - useOpenAIWhisper?: boolean | null | undefined; + useOpenAIWhisper: boolean; elevenLabsApiKey?: string | null | undefined; } = { openAIApiKey: localStorage.getItem('openai-api-key'), - useOpenAIWhisper: localStorage.getItem('use-openai-whisper') === 'true', + useOpenAIWhisper: false, elevenLabsApiKey: localStorage.getItem('elevenlabs-api-key'), };