Skip to content

feat: add language fallback handler for Kokoro TTS#124

Open
udaykumarreddykasaram07-eng wants to merge 2 commits intosugarlabs:mainfrom
udaykumarreddykasaram07-eng:feat/language-fallback-handler
Open

feat: add language fallback handler for Kokoro TTS#124
udaykumarreddykasaram07-eng wants to merge 2 commits intosugarlabs:mainfrom
udaykumarreddykasaram07-eng:feat/language-fallback-handler

Conversation

@udaykumarreddykasaram07-eng
Copy link
Copy Markdown

Adds utils/language_fallback.py to safely handle language codes for Kokoro TTS.

What this fixes:

  • Prevents crashes when unsupported language codes are passed to KPipeline
  • Falls back to English with a warning log instead of failing silently
  • Maps ISO codes (hi, fr), Kokoro codes (h, f), and names (hindi, french) correctly
  • Adds helper functions for future language UI and G2P routing

How to test:
python3 -c "from utils.language_fallback import resolve_lang_code; print(resolve_lang_code('hi'))"

Output: ('h', True)

python3 -c "from utils.language_fallback import resolve_lang_code; print(resolve_lang_code('xyz'))"

Output: ('a', False) + warning log

Relates to GSoC 2026 Speak-AI Multilingual Support proposal.

PR sugarlabs#24 contained an invalid SVG that GitHub cannot render.
This provides a valid, properly structured SVG icon that:
- Renders correctly in all SVG viewers
- Uses Sugar orange color palette
- Adds AI speech bubble to distinguish from original Speak
- Adds sound waves to represent TTS voice synthesis

Closes #2
Adds utils/language_fallback.py with:
- resolve_lang_code(): maps ISO codes, names, or Kokoro codes
  to valid Kokoro lang_codes with graceful English fallback
- get_supported_languages(): returns all supported languages
- is_non_latin_script(): flags languages needing G2P preprocessing
  (Hindi, Japanese, Chinese) before passing to KPipeline

Prevents silent crashes when unsupported language codes are passed
to KPipeline. Adds proper logging when fallback occurs.

Relates to GSoC 2026 Speak-AI Multilingual Support proposal.
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.

1 participant