Skip to content

fix(audio-captions): check for Speech Recognition API support before accessing voices - #23348

Merged
antobinary merged 1 commit into
bigbluebutton:v3.0.x-releasefrom
Arthurk12:30/issue/23316
Jun 10, 2025
Merged

antobinary merged 1 commit into
bigbluebutton:v3.0.x-releasefrom
Arthurk12:30/issue/23316

Conversation

@Arthurk12

Copy link
Copy Markdown
Member

What does this PR do?

Add a missing check to ensure the browser supports the Speech Recognition API before attempting to access supported speech voices.

Closes Issue(s)

Closes #23316

…accessing voices

Add a missing check to ensure the browser supports the Speech Recognition
API before attempting to access supported speech voices.
@coderabbitai

coderabbitai Bot commented Jun 9, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The code update replaces a direct check for the presence of window.speechSynthesis in the getSpeechVoices function with a call to the hasSpeechRecognitionSupport() function, which is imported from another module. This change centralizes the logic for determining speech recognition support and modifies the condition under which speech voices are retrieved, making it dependent on the result of the new support-checking function.

Sequence Diagram(s)

sequenceDiagram
    participant UI_Component
    participant Service
    participant SpeechService

    UI_Component->>Service: getSpeechVoices()
    Service->>SpeechService: hasSpeechRecognitionSupport()
    alt Speech recognition supported
        Service-->>UI_Component: Return available voices
    else Not supported
        Service-->>UI_Component: Return null
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure browser transcription support is correctly detected in Firefox (#23316) ✅

Suggested reviewers

  • Tainan404
  • ramonlsouza
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2025

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39914a2 and b29ac75.

📒 Files selected for processing (1)
  • bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (1)
bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts (1)

7-7:

Details

✅ Verification successful

Verify the semantic correctness of the imported function.

The imported function hasSpeechRecognitionSupport suggests it checks for Speech Recognition API support, but this function uses the Speech Synthesis API (window.speechSynthesis). Please ensure the function checks for the correct API.


🏁 Script executed:

#!/bin/bash
# Description: Check what hasSpeechRecognitionSupport() actually validates
# Expected: The function should check for Speech Synthesis API or both APIs

# Find the implementation of hasSpeechRecognitionSupport function
rg -A 10 "hasSpeechRecognitionSupport" --type ts

Length of output: 8566


Import and API support check is correct

The hasSpeechRecognitionSupport function not only verifies SpeechRecognitionAPI but also checks for window.speechSynthesis and valid environments, so gating getVoices() behind it will prevent runtime errors. No changes needed here.

if (!isWebSpeechApi()) return LANGUAGES;

if (!window.speechSynthesis) return null;
if (!hasSpeechRecognitionSupport()) return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Risk of runtime error - missing direct Speech Synthesis API check.

While the hasSpeechRecognitionSupport() check is added, the function still accesses window.speechSynthesis.getVoices() on lines 74-77 without directly verifying that window.speechSynthesis exists. This could cause runtime errors if the Speech Synthesis API is unavailable but the recognition support check passes.

Consider adding a direct check for the Speech Synthesis API:

  if (!isWebSpeechApi()) return LANGUAGES;
  if (!hasSpeechRecognitionSupport()) return null;
+ if (!window.speechSynthesis) return null;

🏁 Script executed:

#!/bin/bash
# Description: Check how getSpeechVoices is used to understand impact of returning null
# Expected: Find usage patterns and error handling for null return values

# Find all usages of getSpeechVoices function
rg -A 5 -B 2 "getSpeechVoices" --type ts --type tsx

Length of output: 79


I’d like to dig deeper to confirm how getSpeechVoices and window.speechSynthesis are used in service.ts. Let’s locate both the definition/usage of getSpeechVoices and any direct references to speechSynthesis in that file:


🏁 Script executed:

#!/bin/bash
# 1. Find any definition or calls to getSpeechVoices in the repo
rg -n "getSpeechVoices" .

# 2. Check for direct speechSynthesis usage in the service file
rg -n "speechSynthesis" bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts

# 3. Dump lines 60–100 of the service to inspect the context around the check
sed -n '60,100p' bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts

Length of output: 2309


Add a Speech Synthesis API guard in getSpeechVoices

The hasSpeechRecognitionSupport() check covers only recognition; if window.speechSynthesis is missing, calling .getVoices() will throw.

Files to update:

  • bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts

Suggested diff:

 export const getSpeechVoices = () => {
   const LANGUAGES = window.meetingClientSettings.public.app.audioCaptions.language.available;
   if (!isWebSpeechApi()) return LANGUAGES;
   if (!hasSpeechRecognitionSupport()) return null;
+  if (
+    typeof window.speechSynthesis !== 'object' ||
+    typeof window.speechSynthesis.getVoices !== 'function'
+  ) {
+    return null;
+  }
 
   return unique(
     window
       .speechSynthesis
       .getVoices()
       .map((v) => v.lang)
       .filter((v) => LANGUAGES.includes(v)),
   );
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!hasSpeechRecognitionSupport()) return null;
export const getSpeechVoices = () => {
const LANGUAGES = window.meetingClientSettings.public.app.audioCaptions.language.available;
if (!isWebSpeechApi()) return LANGUAGES;
if (!hasSpeechRecognitionSupport()) return null;
if (
typeof window.speechSynthesis !== 'object' ||
typeof window.speechSynthesis.getVoices !== 'function'
) {
return null;
}
return unique(
window
.speechSynthesis
.getVoices()
.map((v) => v.lang)
.filter((v) => LANGUAGES.includes(v)),
);
};
🤖 Prompt for AI Agents
In
bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts
at line 71, the code checks for speech recognition support but does not verify
if the Speech Synthesis API (window.speechSynthesis) exists before calling
getVoices(), which can cause runtime errors. To fix this, add a direct check to
confirm window.speechSynthesis is defined before accessing getVoices(), and
return null if it is not available, ensuring safe usage of the Speech Synthesis
API.

@github-actions

github-actions Bot commented Jun 9, 2025

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have passed!

@antobinary antobinary added this to the Release 3.0 milestone Jun 10, 2025
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.

[3.0] Firefox acts as if browser transcriptions are supported when they're not

2 participants