-
Notifications
You must be signed in to change notification settings - Fork 52
feat(tts): prioritize regional scripts over English in Sarvam TTS #460
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
Conversation
- Prioritize regional languages when mixed with English words
WalkthroughTwo targeted logic improvements were made: the script detection function now prioritizes regional Indian scripts over English, returning any detected regional script immediately; meanwhile, logging spam filters were expanded to exclude additional binary data patterns from specific loggers. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the Sarvam TTS language detection to prioritize regional Indian languages over English when both scripts are present in the text, addressing the common pattern of mixing English words with regional languages in Indian speech.
Key Changes:
- Modified script detection logic to prioritize any regional language characters over English
- Added logging filters to suppress verbose binary websocket messages
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
app/ai/voice/tts/sarvam.py |
Updated detect_script() function to return regional language when any regional script is detected, even if mixed with English words |
app/core/logger/__init__.py |
Added filters to suppress "> BINARY" and "< BINARY" log messages from websocket logging spam |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # If ANY regional language is detected, use it (prioritize over English) | ||
| # This handles mixed text like "హలో Manas sir!" → Telugu | ||
| if regional_script and max_regional_count > 0: |
Copilot
AI
Dec 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition if regional_script and max_regional_count > 0 is redundant. If max_regional_count > 0, then regional_script will always be set to a non-None value based on the loop logic in lines 78-81. The check for regional_script being truthy is unnecessary and can be simplified to just if max_regional_count > 0.
| if regional_script and max_regional_count > 0: | |
| if max_regional_count > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/ai/voice/tts/sarvam.py (1)
85-85: Optional: Simplify the conditional check.The condition
regional_script and max_regional_count > 0includes a redundant check. Ifmax_regional_count > 0, thenregional_scriptmust be non-None (it was set in the loop). The simplified conditionmax_regional_count > 0would be sufficient.🔎 Proposed simplification
- if regional_script and max_regional_count > 0: + if max_regional_count > 0: return regional_script
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
app/ai/voice/tts/sarvam.pyapp/core/logger/__init__.py
🧰 Additional context used
🪛 Ruff (0.14.10)
app/ai/voice/tts/sarvam.py
93-93: Consider moving this statement to an else block
(TRY300)
🔇 Additional comments (3)
app/core/logger/__init__.py (1)
81-82: LGTM: Binary data spam filters added correctly.The new filter conditions for "> BINARY" and "< BINARY" message prefixes are consistent with existing spam filtering patterns and will effectively reduce logging noise.
app/ai/voice/tts/sarvam.py (2)
54-59: Clear documentation of the new prioritization behavior.The updated docstring accurately describes the regional-first detection logic and provides a helpful example.
75-93: No breaking changes identified.The behavioral change is safe. The
detect_scriptfunction has only one consumer (_switch_language_if_needed), which usesSCRIPT_TO_SARVAM_LANG.get(detected_script, "en-IN")with a fallback, so it's protected against any return value. The mapping covers all 10 possible script return values (9 regional scripts + "english"), and the implementation is correct and well-documented.Note: There are currently no unit tests for
detect_script, so there are no existing tests to break.
|
Not needed anymore, using cartesia TTS for regional languages now. |
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.