Skip to content

fix(transcription): Properly test if a language is available - #25043

Closed
lfzawacki wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
lfzawacki:v3.0.x-develop
Closed

lfzawacki wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
lfzawacki:v3.0.x-develop

Conversation

@lfzawacki

Copy link
Copy Markdown
Contributor

The old getSpeechVoices method was used for the purpose of filtering supported languages for the browser SpeechRecognition API. This was the wrong API to call and in some cases like for example Catalan it would result in the language being configured in the app.audioCaptions.language.available array but no actually showing in the dropdow list.

This new code attempts to call the correct API if it's present in the browser and now properly let's us configure and select all valid languages for a given SpeechRecognition API instance.

@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR updates the audio captions component to determine available transcription languages by querying browser speech recognition support instead of speech synthesis voices. The service module adds two new functions: isSpeechRecognitionLanguageSupported() for individual language detection with cross-browser compatibility, and getAvailableTranscriptionLanguages() which filters configured languages by their recognition support with result caching. The component's language initialization switches to use the new service method, preserving the existing selection and GraphQL mutation logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(transcription): Properly test if a language is available' directly reflects the main change—replacing the incorrect getSpeechVoices method with proper language availability testing via the SpeechRecognition API.
Description check ✅ Passed The description clearly explains the problem (getSpeechVoices was the wrong API, causing languages like Catalan to be unavailable in the dropdown) and the solution (calling the correct SpeechRecognition API).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

sonarqubecloud Bot commented May 7, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@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

🧹 Nitpick comments (1)
bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/captions/component.tsx (1)

150-157: ⚡ Quick win

voicesList state and its useEffect are vestigial — consider removing them

getAvailableTranscriptionLanguages() is synchronous and module-level–cached, so voices is stable across renders. The useEffect only copies it once into voicesList, but voices || voicesList always prefers voices when it is non-null (including when it is an empty array [], which is truthy). The voicesList fallback is effectively unreachable dead code.

Once the critical async fix is applied, the component will need to manage async state explicitly anyway — at that point this pattern can be replaced cleanly with a single useState<string[] | null>(null) initialized via a useEffect + await.

Also applies to: 173-173

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/captions/component.tsx`
around lines 150 - 157, Remove the dead state and effect: delete the voicesList
useState and the useEffect that copies getAvailableTranscriptionLanguages() into
it, and replace uses of voicesList with the direct voices variable returned by
getAvailableTranscriptionLanguages(); keep getAvailableTranscriptionLanguages()
as the single source of truth now and later refactor to a useState<string[] |
null> + async useEffect when the async loading change is implemented.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts`:
- Around line 76-90: The isSpeechRecognitionLanguageSupported function must be
made async and call SR.available with the correct signature and await its
Promise: call SR.available({ langs: [lang], processLocally: false }) (or omit
processLocally if not needed), await the returned AvailabilityStatus and return
a boolean (e.g. status === "available"); then update the caller that builds
cachedTranscriptionLanguages to handle the async results (e.g. map langs to
Promises, await Promise.all, filter by the resolved booleans, or move the
filtering into a useEffect/state flow) so the language filter is no longer a
no-op; refer to isSpeechRecognitionLanguageSupported and the
cachedTranscriptionLanguages producer in your changes.

---

Nitpick comments:
In
`@bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/captions/component.tsx`:
- Around line 150-157: Remove the dead state and effect: delete the voicesList
useState and the useEffect that copies getAvailableTranscriptionLanguages() into
it, and replace uses of voicesList with the direct voices variable returned by
getAvailableTranscriptionLanguages(); keep getAvailableTranscriptionLanguages()
as the single source of truth now and later refactor to a useState<string[] |
null> + async useEffect when the async loading change is implemented.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 256b1b10-a4dc-4e79-b1f9-e8202be0d3c7

📥 Commits

Reviewing files that changed from the base of the PR and between c8a489f and 5fef9c0.

📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/captions/component.tsx
  • bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts

Comment on lines +76 to +90
const isSpeechRecognitionLanguageSupported = (lang: string): boolean => {
try {
// @ts-ignore - SR types is not yet in the TS types
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
if (!SR) return false;
if (typeof SR.available === 'function') {
return SR.available(lang);
}
// If SpeechRecognition.available() is not implemented in this browser,
// fall back to assuming all languages are supported.
return true;
} catch (e) {
return false;
}
};

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.

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine the service.ts file
find . -name "service.ts" -path "*/audio-captions/*" | head -5

Repository: bigbluebutton/bigbluebutton

Length of output: 258


🏁 Script executed:

# Get more context around the function
fd service.ts -path "*/audio-captions/*" -x wc -l {}

Repository: bigbluebutton/bigbluebutton

Length of output: 240


🏁 Script executed:

# Find the exact file path
fd -i service.ts | grep -i "audio.*captions"

Repository: bigbluebutton/bigbluebutton

Length of output: 254


🏁 Script executed:

# Read the service.ts file to verify the code and context
cat -n ./bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts

Repository: bigbluebutton/bigbluebutton

Length of output: 6230


🏁 Script executed:

# Check the entire file size first
wc -l ./bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts

Repository: bigbluebutton/bigbluebutton

Length of output: 165


🏁 Script executed:

# Check if there are any tests for this function
find . -name "*.test.*" -o -name "*.spec.*" | xargs grep -l "isSpeechRecognitionLanguageSupported" 2>/dev/null || echo "No tests found"

Repository: bigbluebutton/bigbluebutton

Length of output: 86


🏁 Script executed:

# Search for any comments or documentation about SpeechRecognition.available
rg "SpeechRecognition\.available" -B 3 -A 3

Repository: bigbluebutton/bigbluebutton

Length of output: 2854


🏁 Script executed:

# Look for any usage of SR.available in the codebase
rg "\.available\(" -B 2 -A 2 --type ts --type js | head -50

Repository: bigbluebutton/bigbluebutton

Length of output: 2359


🌐 Web query:

Web Speech API SpeechRecognition.available() method specification

💡 Result:

The SpeechRecognition.available is a static method of the Web Speech API that checks whether specified languages are available for speech recognition. It returns a Promise resolving to an AvailabilityStatus enum value: 'available' (all languages supported, on-device if processLocally:true or on-device/remote if false), 'downloading' (language pack downloading, on-device only), 'downloadable' (supported but not installed, on-device only), or 'unavailable' (not supported for at least one language).[1][2][3] Syntax: SpeechRecognition.available(options), where options is an object with: - langs: array of BCP 47 language tags (e.g., ['en-US']; empty array resolves to 'unavailable') - processLocally: boolean (default false; true checks only on-device)[1][2] Access is controlled by the 'on-device-speech-recognition' Permissions-Policy; blocked policies cause failure.[1][2] This method is not in the original 2012 W3C draft[4] but appears in recent drafts (e.g., 2025)[3] and MDN docs (updated 2025).[2][5][6]

Citations:


🌐 Web query:

SpeechRecognition.available() Promise AvailabilityStatus MDN Web Speech API

💡 Result:

SpeechRecognition.available is a static method in the Web Speech API that returns a Promise resolving to an AvailabilityStatus enum value indicating whether specified languages are available for speech recognition [1][2]. It checks availability for on-device or remote (default) recognition based on options [1][2].

Citations:


🌐 Web query:

SpeechRecognition available() static method signature parameters

💡 Result:

The SpeechRecognition.available static method has the following signature: available(options) Parameters: - options: An object with: - langs: Array of BCP 47 language tags (strings) to check for availability. Empty array resolves to 'unavailable'.[1][2][3] - processLocally (optional, default false): Boolean; true checks only on-device recognition, false checks on-device or remote.[1][2][3] It returns a Promise resolving to an AvailabilityStatus enum: 'available', 'downloading', 'downloadable', or 'unavailable'.[1][4] This is from the Web Speech API, experimental with limited browser support.[1][3]

Citations:


SR.available() is called with the wrong signature and returns a Promise that is always truthy — the language filter is a complete no-op

Per the Web Speech API spec, SpeechRecognition.available() is an async method that returns a Promise resolving to an AvailabilityStatus enum ("available", "downloading", "downloadable", or "unavailable"). The correct signature is SpeechRecognition.available({ langs: ["en-US"], processLocally?: boolean }).

The code has two critical problems:

  1. Wrong argument type: SR.available(lang) passes a plain string; the spec requires { langs: string[] }.
  2. Unhandled Promise: The function returns a Promise object directly without awaiting it. Since a Promise is always truthy, .filter(isSpeechRecognitionLanguageSupported) includes every language regardless of support — the entire filtering logic is a no-op.

Result: In browsers implementing the Web Speech API, cachedTranscriptionLanguages always equals unique(LANGUAGES), defeating the stated goal of filtering by language support.

The fix requires making isSpeechRecognitionLanguageSupported async and updating the caller to handle the Promise:

🐛 Proposed fix
-const isSpeechRecognitionLanguageSupported = (lang: string): boolean => {
+const isSpeechRecognitionLanguageSupported = async (lang: string): Promise<boolean> => {
   try {
     // `@ts-ignore` - SR types is not yet in the TS types
     const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
     if (!SR) return false;
     if (typeof SR.available === 'function') {
-      return SR.available(lang);
+      const result = await SR.available({ langs: [lang] });
+      return result !== 'unavailable';
     }
-    // If SpeechRecognition.available() is not implemented in this browser,
-    // fall back to assuming all languages are supported.
+    // Browser supports SR but not the available() API; assume all languages work.
     return true;
   } catch (e) {
     return false;
   }
 };

-export const getAvailableTranscriptionLanguages = (): string[] | null => {
+export const getAvailableTranscriptionLanguages = async (): Promise<string[] | null> => {
   const LANGUAGES: string[] = window.meetingClientSettings.public.app.audioCaptions.language.available;
   if (!isWebSpeechApi()) return LANGUAGES;
   if (!hasSpeechRecognitionSupport()) return null;
   if (cachedTranscriptionLanguages !== null) return cachedTranscriptionLanguages;
-  cachedTranscriptionLanguages = unique(LANGUAGES).filter(isSpeechRecognitionLanguageSupported);
+  const results = await Promise.all(unique(LANGUAGES).map(isSpeechRecognitionLanguageSupported));
+  cachedTranscriptionLanguages = unique(LANGUAGES).filter((_, i) => results[i]);
   return cachedTranscriptionLanguages;
 };

The calling component will need to handle the async result (e.g., via useEffect + state, or a custom hook).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bigbluebutton-html5/imports/ui/components/audio/audio-graphql/audio-captions/service.ts`
around lines 76 - 90, The isSpeechRecognitionLanguageSupported function must be
made async and call SR.available with the correct signature and await its
Promise: call SR.available({ langs: [lang], processLocally: false }) (or omit
processLocally if not needed), await the returned AvailabilityStatus and return
a boolean (e.g. status === "available"); then update the caller that builds
cachedTranscriptionLanguages to handle the async results (e.g. map langs to
Promises, await Promise.all, filter by the resolved booleans, or move the
filtering into a useEffect/state flow) so the language filter is no longer a
no-op; refer to isSpeechRecognitionLanguageSupported and the
cachedTranscriptionLanguages producer in your changes.

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

🚨 Automated tests failed

@lfzawacki

Copy link
Copy Markdown
Contributor Author

This is actually more complicated than I thought here's an issue to track this problem: #25068

@antobinary antobinary mentioned this pull request May 15, 2026
16 of 17 tasks
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