修复语音识别小bug

This commit is contained in:
sijinhui 2024-03-28 19:25:51 +08:00
parent 24eb62f5e9
commit 868cf96cc8

View File

@ -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); // 错误处理