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 speech recognition example in documentation: button logic and error handling #20

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

saleheen-dev
Copy link
Contributor

This pull request addresses two issues in the speech recognition example code:

  1. Fixed the button rendering logic:
    Corrected the recognizing state in the conditional rendering of the Start/Stop button. The "Start" button now shows when not recognizing, and "Stop" when recognizing.

  2. Improved error handling in the handleStart function:
    Added try/catch block and made the function asynchronous to properly handle potential errors during permission request and speech recognition start.

These changes improve the accuracy and robustness of the documentation example, ensuring that developers can implement speech recognition in their Expo projects more reliably.

Testing:

  • The updated code has been tested in an Expo project to ensure it functions as expected.
  • The Start/Stop button now correctly reflects the current state of speech recognition.
  • Error handling has been verified to catch and log potential issues.

Please take a look at these changes and let me know if you need any more changes.

Copy link
Owner

@jamsch jamsch left a comment

Choose a reason for hiding this comment

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

Hey @Stechno, good spotting!

Just a few small changes necessary

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@saleheen-dev
Copy link
Contributor Author

Thank you @jamsch for the feedback. I've made the following changes:

  1. Removed the try-catch block from the handleVoice function.
  2. Adjusted the error handling to use useSpeechRecognitionEvent("error", ...) instead.
  3. Removed the async/await from ExpoSpeechRecognitionModule.start() as it's synchronous.

Regarding your question about uncaught errors: No, I haven't encountered any uncaught errors in my testing. I initially added the try-catch block thinking it might help with potential permission-related errors on older Android versions. However, I agree with your assessment that it's unnecessary, especially given that Expo handles these scenarios. I've removed that code as per your suggestion.

I've tested these changes, and everything seems to be working.

Thank you again for your guidance and for helping improve the documentation!

Copy link
Owner

@jamsch jamsch left a comment

Choose a reason for hiding this comment

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

Thank you!

@jamsch jamsch merged commit f2bc688 into jamsch:main Sep 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants