From 868cf96cc8ed9967a71aa5f7b90debeaf340eb8b Mon Sep 17 00:00:00 2001 From: sijinhui Date: Thu, 28 Mar 2024 19:25:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=AD=E9=9F=B3=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/voice-input.tsx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/components/voice-input.tsx b/app/components/voice-input.tsx index 0259968bd..598b7322e 100644 --- a/app/components/voice-input.tsx +++ b/app/components/voice-input.tsx @@ -47,8 +47,7 @@ export default function VoiceInput({ function onRecognizedResult(result: SpeechRecognitionResult) { // setVoiceInputText(""); - setVoiceInputText(`${result.text}`); - + setVoiceInputText(`${result.text ?? ""}`); let intentJson = result.properties.getProperty( ms_audio_sdk.PropertyId.LanguageUnderstandingServiceResponse_JsonResult, ); @@ -57,8 +56,6 @@ export default function VoiceInput({ } // setTempUserInput(""); - console.log("3333", tempUserInput, "2", voiceInputText); - // if (result?.translations) { // let resultJson = JSON.parse(result.json); // resultJson['privTranslationPhrase']['Translation']['Translations'].forEach( @@ -89,12 +86,11 @@ export default function VoiceInput({ setUserInput( tempUserInput + voiceInputText.replace(/(.*)(^|[\r\n]+).*\[\.\.\.][\r\n]+/, "$1$2") + - `${result.text} [...]`, + `${result.text ?? ""} [...]`, ); - setVoiceInputText( voiceInputText.replace(/(.*)(^|[\r\n]+).*\[\.\.\.][\r\n]+/, "$1$2") + - `${result.text} [...]`, + `${result.text ?? ""} [...]`, ); } @@ -130,12 +126,10 @@ export default function VoiceInput({ recognizer.current.recognizeOnceAsync( (result) => { onRecognizedResult(result); - - setUserInput(tempUserInput + voiceInputText ?? "" + `${result.text}`); - // setVoiceInputText(result.text); - console.log("result", result.text); + setUserInput( + tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`, + ); setVoiceInputLoading(false); - // recognizer.close(); }, (err) => { console.error("Recognition error: ", err); // 错误处理