Skip to content

fix(kokoro): catch unsupported language RuntimeError and return 422 - #669

Open
Archlie wants to merge 1 commit into
speaches-ai:masterfrom
Archlie:fix/chinese-tts-unsupported-lang-error
Open

fix(kokoro): catch unsupported language RuntimeError and return 422#669
Archlie wants to merge 1 commit into
speaches-ai:masterfrom
Archlie:fix/chinese-tts-unsupported-lang-error

Conversation

@Archlie

@Archlie Archlie commented Aug 9, 2026

Copy link
Copy Markdown

Summary

When a Kokoro voice uses a language not supported by the phonemizer backend (e.g. Chinese zh with espeak), the RuntimeError was unhandled, causing a 500 Internal Server Error.

This PR fixes the issue by:

  1. kokoro.py: Catching RuntimeError with 'not supported' in the message during tts.create_stream() and re-raising as ValueError with a clear error message identifying the unsupported language and voice.

  2. speech.py: Generalizing the ValueError handling in the speech router to return 422 for all validation errors (not just speed-related ones), since any ValueError from the handler represents invalid client input.

Before (500 error)

RuntimeError: language "zh" is not supported by the espeak backend

After (422 with clear message)

{
  "detail": "Language 'zh' is not supported by the phonemizer backend for voice 'zf_xiaobei'. language \"zh\" is not supported by the espeak backend"
}

Closes #647

When a Kokoro voice uses a language not supported by the phonemizer
backend (e.g. Chinese 'zh' with espeak), the RuntimeError was
unhandled, causing a 500 Internal Server Error.

Fix: catch RuntimeError with 'not supported' in the message in
KokoroModelManager.handle_speech_request and re-raise as ValueError
so the speech router returns a proper 422 with a clear error message.

Also generalize the speech router's ValueError handling to return 422
for all validation errors, not just speed-related ones.

Closes speaches-ai#647
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.

Chinese TTS requests to /v1/audio/speech fail: RuntimeError: language "zh" is not supported by the espeak backend

1 participant