From 80a7a1d9d0025059ca544231a2af6b2c2e9eb8ab Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Sat, 12 Oct 2024 16:54:02 +0800 Subject: [PATCH] chore: wip --- app/components/chat.tsx | 8 ++++++-- app/constant.ts | 4 ++-- app/locales/cn.ts | 5 +++-- app/locales/en.ts | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 46e4856f1..317343574 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -370,6 +370,7 @@ export function ChatAction(props: { text: string; icon: JSX.Element; onClick: () => void; + recording?: boolean; }) { const iconRef = useRef(null); const textRef = useRef(null); @@ -378,7 +379,7 @@ export function ChatAction(props: { icon: 16, }); - function updateWidth() { + function updateWidth(recording?: boolean) { if (!iconRef.current || !textRef.current) return; const getWidth = (dom: HTMLDivElement) => dom.getBoundingClientRect().width; const textWidth = getWidth(textRef.current); @@ -559,7 +560,7 @@ export function ChatActions(props: { useEffect(() => { if (isFirefox()) config.sttConfig.engine = FIREFOX_DEFAULT_STT_ENGINE; setSpeechApi( - config.sttConfig.engine === DEFAULT_STT_ENGINE + config.sttConfig.engine !== DEFAULT_STT_ENGINE ? new WebTranscriptionApi((transcription) => onRecognitionEnd(transcription), ) @@ -570,6 +571,7 @@ export function ChatActions(props: { }, []); const startListening = async () => { + showToast(Locale.Chat.StartSpeak); if (speechApi) { await speechApi.start(); setIsListening(true); @@ -582,6 +584,7 @@ export function ChatActions(props: { await speechApi.stop(); setIsListening(false); } + showToast(Locale.Chat.CloseSpeak); }; const onRecognitionEnd = (finalTranscript: string) => { console.log(finalTranscript); @@ -832,6 +835,7 @@ export function ChatActions(props: { } text={isListening ? Locale.Chat.StopSpeak : Locale.Chat.StartSpeak} icon={isListening ? : } + recording={isListening} /> )} diff --git a/app/constant.ts b/app/constant.ts index 63954d2e3..44b53ac4d 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -271,8 +271,8 @@ export const DEFAULT_TTS_VOICES = [ "shimmer", ]; -export const DEFAULT_STT_ENGINE = "Web Speech API"; -export const DEFAULT_STT_ENGINES = ["Web Speech API", "OpenAI Whisper"]; +export const DEFAULT_STT_ENGINE = "OpenAI Whisper"; +export const DEFAULT_STT_ENGINES = ["OpenAI Whisper", "Web Speech API"]; export const DEFAULT_STT_LANGUAGE = "zh-CN"; export const DEFAULT_STT_LANGUAGES = [ "zh-CN", // 中文(简体) diff --git a/app/locales/cn.ts b/app/locales/cn.ts index eaa799a04..e3b36f0cc 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -92,8 +92,9 @@ const cn = { return inputHints + ",/ 触发补全,: 触发命令"; }, Send: "发送", - StartSpeak: "说话", - StopSpeak: "停止", + StartSpeak: "启用语音输入", + CloseSpeak: "关闭语音输入", + StopSpeak: "录音中....点击结束", Config: { Reset: "清除记忆", SaveAs: "存为面具", diff --git a/app/locales/en.ts b/app/locales/en.ts index f715d0889..c9f15c335 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -94,7 +94,8 @@ const en: LocaleType = { }, Send: "Send", StartSpeak: "Start Speak", - StopSpeak: "Stop Speak", + CloseSpeak: "Stop Speak", + StopSpeak: "Recording...", Config: { Reset: "Reset to Default", SaveAs: "Save as Mask",