Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix speech recognition failed, the input box did not restore the default style. #2172

Merged
merged 1 commit into from
Feb 8, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: Fix speech recognition failed, the input box did not restore the default style. --bug=1051969 --user=刘瑞斌 【应用】语音识别失败后输入框没有恢复默认的样式 https://www.tapd.cn/57709429/s/1651864

… default style.

--bug=1051969 --user=刘瑞斌 【应用】语音识别失败后输入框没有恢复默认的样式 https://www.tapd.cn/57709429/s/1651864
Copy link

f2c-ci-robot bot commented Feb 8, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Feb 8, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

.catch((error) => {
recorderLoading.value = false
console.error(`${t('chat.uploadFile.errorMessage')}:`, error)
})
} catch (error) {
recorderLoading.value = false
console.error(`${t('chat.uploadFile.errorMessage')}:`, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code provided has a few issues that could be improved:

  1. Error Handling: The catch block is currently inside the promise callback of .then(). This means it will only handle errors if there's an additional asynchronous operation that occurs after this point. To ensure all errors are handled correctly, you should move the catch outside both promises.

  2. Logging Error Messages: Ensure that $t('chat.uploadFile.errorMessage') returns valid string contents before logging. If not, it might result in a TypeError.

  3. Consistency with Initial State: It’s good to set recorderLoading.value = false; at the beginning of each function call to avoid confusion about its state during error handling or normal execution.

Here’s a revised version of the code addressing these points:

const uploadRecording = async (audioBlob: Blob) => {
  try {
    // Initialize loading status first
    recorderLoading.value = true;

    await audioRecordPromise.then(recordedAudio => {
      console.log("Recording stopped.");
      // Upload recorded audio blob here...
    }).catch(error => {
      console.error(`${$t('chat.uploadFile.errorMessage')}:`, error);
      recorderLoading.value = false;
    });

    await uploadRecordingPromises.forEach(uploadPromise => {
      await uploadPromise.then(response =>
        console.log(`${response.statusText} : ${response.url}`)
      ).catch((error) => {
        recorderLoading.value = false;
        console.error(`${$t('chat.uploadFile.errorMessage')}:`, error);
      });
    });
  } catch (catchErr) {
    console.error(`Unexpected error occurred:`, catchErr);
    recorderLoading.value = false;
  }
};

Key Changes Made:

  • Moved initial setting of recorderLoading.value = false; at the start.
  • Ensured proper nesting where necessary (forEach) and added missing brackets accordingly.
  • Added consistency by logging relevant error messages.
  • Simplified variable names where appropriate for clarity.

@liuruibin liuruibin merged commit 8668796 into main Feb 8, 2025
4 checks passed
@liuruibin liuruibin deleted the pr@main@fix_speech_ branch February 8, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants