From f05e4a889663dbbff0d19a7988f7f08393abf380 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Fri, 29 Mar 2024 08:51:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=BF=AE=E5=A4=8D=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E8=BE=93=E5=85=A5=E6=AE=8B=E7=95=99=E6=96=87=E5=AD=97?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/voice-input.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/components/voice-input.tsx b/app/components/voice-input.tsx index 28f81215d..0b5960c6d 100644 --- a/app/components/voice-input.tsx +++ b/app/components/voice-input.tsx @@ -45,6 +45,13 @@ export default function VoiceInput({ } }, [accessToken]); + useEffect(() => { + if (!userInput || userInput.trim() === "") { + setTempUserInput(""); + setVoiceInputText(""); + } + }, [userInput]); + function onRecognizedResult(result: SpeechRecognitionResult) { // setVoiceInputText(""); setVoiceInputText(`${result.text ?? ""}`); @@ -68,7 +75,7 @@ export default function VoiceInput({ sender: Recognizer, event: SpeechRecognitionCanceledEventArgs, ) { - console.log(event); + console.log("[onCanceled] ", event); // 如果有异常就尝试重新获取 setAccessToken(""); // 展示取消事件 @@ -126,9 +133,19 @@ export default function VoiceInput({ recognizer.current.recognizeOnceAsync( (result) => { onRecognizedResult(result); + console.log( + "1", + tempUserInput, + "2", + voiceInputText ?? "", + "3", + `${result.text ?? ""}`, + ); setUserInput( tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`, ); + setTempUserInput(""); + setVoiceInputText(""); setVoiceInputLoading(false); }, (err) => {