Repository navigation
fix(audio-captions): check for Speech Recognition API support before accessing voices - #23348
Conversation
…accessing voices Add a missing check to ensure the browser supports the Speech Recognition API before attempting to access supported speech voices.
WalkthroughThe code update replaces a direct check for the presence of 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
Assessment against linked issues
Suggested reviewers
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
hasSpeechRecognitionSupportsuggests 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 tsLength of output: 8566
Import and API support check is correct
The
hasSpeechRecognitionSupportfunction not only verifiesSpeechRecognitionAPIbut also checks forwindow.speechSynthesisand valid environments, so gatinggetVoices()behind it will prevent runtime errors. No changes needed here.
| if (!isWebSpeechApi()) return LANGUAGES; | ||
|
|
||
| if (!window.speechSynthesis) return null; | ||
| if (!hasSpeechRecognitionSupport()) return null; |
There was a problem hiding this comment.
💡 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 tsxLength 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.tsLength 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.
| 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.
Automated tests Summary✅ All the CI tests have passed! |



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