From bd1a8dcc3a3e27d16f8b01b7180d139e86070b76 Mon Sep 17 00:00:00 2001 From: Hk-Gosuto Date: Tue, 26 Mar 2024 17:02:41 +0800 Subject: [PATCH] fix: #236 --- app/components/chat.tsx | 3 +++ app/components/stt-config.tsx | 41 +++++++++++++++++++---------------- app/constant.ts | 1 + app/utils/speech.ts | 2 ++ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 4ad66a8ce..ae9f5881d 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -68,6 +68,7 @@ import { getMessageImages, isVisionModel, compressImage, + isFirefox, } from "../utils"; import dynamic from "next/dynamic"; @@ -92,6 +93,7 @@ import { useNavigate } from "react-router-dom"; import { CHAT_PAGE_SIZE, DEFAULT_STT_ENGINE, + FIREFOX_DEFAULT_STT_ENGINE, LAST_INPUT_KEY, ModelProvider, Path, @@ -903,6 +905,7 @@ function _Chat() { } }); // eslint-disable-next-line react-hooks/exhaustive-deps + if (isFirefox()) config.sttConfig.engine = FIREFOX_DEFAULT_STT_ENGINE; setSpeechApi( config.sttConfig.engine === DEFAULT_STT_ENGINE ? new WebTranscriptionApi((transcription) => diff --git a/app/components/stt-config.tsx b/app/components/stt-config.tsx index 8ba9176d9..f83d28030 100644 --- a/app/components/stt-config.tsx +++ b/app/components/stt-config.tsx @@ -3,6 +3,7 @@ import { STTConfig, STTConfigValidator } from "../store"; import Locale from "../locales"; import { ListItem, Select } from "./ui-lib"; import { DEFAULT_STT_ENGINES } from "../constant"; +import { isFirefox } from "../utils"; export function STTConfigList(props: { sttConfig: STTConfig; @@ -24,25 +25,27 @@ export function STTConfigList(props: { } > - - - + {!isFirefox() && ( + + + + )} ); } diff --git a/app/constant.ts b/app/constant.ts index 4712a1019..e081e2bff 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -136,6 +136,7 @@ export const DEFAULT_TTS_VOICES = [ export const DEFAULT_STT_ENGINE = "WebAPI"; export const DEFAULT_STT_ENGINES = ["WebAPI", "OpenAI Whisper"]; +export const FIREFOX_DEFAULT_STT_ENGINE = "OpenAI Whisper"; export const DEFAULT_MODELS = [ { diff --git a/app/utils/speech.ts b/app/utils/speech.ts index 06883d703..dc8102879 100644 --- a/app/utils/speech.ts +++ b/app/utils/speech.ts @@ -1,5 +1,6 @@ import { ChatGPTApi } from "../client/platforms/openai"; import { getSTTLang } from "../locales"; +import { isFirefox } from "../utils"; export type TranscriptionCallback = (transcription: string) => void; @@ -94,6 +95,7 @@ export class WebTranscriptionApi extends SpeechApi { constructor(transcriptionCallback?: TranscriptionCallback) { super(); + if (isFirefox()) return; const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;