mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-02 08:06:38 +08:00
最后修复语音输入残留文字的bug
This commit is contained in:
parent
23eeff047a
commit
f05e4a8896
@ -45,6 +45,13 @@ export default function VoiceInput({
|
|||||||
}
|
}
|
||||||
}, [accessToken]);
|
}, [accessToken]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!userInput || userInput.trim() === "") {
|
||||||
|
setTempUserInput("");
|
||||||
|
setVoiceInputText("");
|
||||||
|
}
|
||||||
|
}, [userInput]);
|
||||||
|
|
||||||
function onRecognizedResult(result: SpeechRecognitionResult) {
|
function onRecognizedResult(result: SpeechRecognitionResult) {
|
||||||
// setVoiceInputText("");
|
// setVoiceInputText("");
|
||||||
setVoiceInputText(`${result.text ?? ""}`);
|
setVoiceInputText(`${result.text ?? ""}`);
|
||||||
@ -68,7 +75,7 @@ export default function VoiceInput({
|
|||||||
sender: Recognizer,
|
sender: Recognizer,
|
||||||
event: SpeechRecognitionCanceledEventArgs,
|
event: SpeechRecognitionCanceledEventArgs,
|
||||||
) {
|
) {
|
||||||
console.log(event);
|
console.log("[onCanceled] ", event);
|
||||||
// 如果有异常就尝试重新获取
|
// 如果有异常就尝试重新获取
|
||||||
setAccessToken("");
|
setAccessToken("");
|
||||||
// 展示取消事件
|
// 展示取消事件
|
||||||
@ -126,9 +133,19 @@ export default function VoiceInput({
|
|||||||
recognizer.current.recognizeOnceAsync(
|
recognizer.current.recognizeOnceAsync(
|
||||||
(result) => {
|
(result) => {
|
||||||
onRecognizedResult(result);
|
onRecognizedResult(result);
|
||||||
|
console.log(
|
||||||
|
"1",
|
||||||
|
tempUserInput,
|
||||||
|
"2",
|
||||||
|
voiceInputText ?? "",
|
||||||
|
"3",
|
||||||
|
`${result.text ?? ""}`,
|
||||||
|
);
|
||||||
setUserInput(
|
setUserInput(
|
||||||
tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`,
|
tempUserInput + (voiceInputText ?? "") + `${result.text ?? ""}`,
|
||||||
);
|
);
|
||||||
|
setTempUserInput("");
|
||||||
|
setVoiceInputText("");
|
||||||
setVoiceInputLoading(false);
|
setVoiceInputLoading(false);
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user