Conversation
…multilingual support) The 'language' config field in tts.openai.language was read but never passed to the API. This caused Kokoro (and other OpenAI-compatible TTS backends that support lang_code) to default to English phonemization regardless of the configured language. Now passes lang_code via extra_body when language is set in config.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused OpenAI-compatible TTS improvement. The premise remains valid on current main: tools/tts_tool.py:1029-1068 reads OpenAI model, voice, base URL, and speed, then calls audio.speech.create() without forwarding a language value.
Problems
- The PR adds request construction behavior without regression coverage.
tests/tools/test_tts_speed.py:71-114already capturesaudio.speech.create()kwargs, but has nolang_codecase. - The setting is not documented in the OpenAI TTS config example at
website/docs/user-guide/features/tts.md:54-58, which currently documents the compatible-endpointbase_urloverride.
Suggested changes
- Add tests for configured
languageforwarding asextra_body={"lang_code": ...}and omission when unset. - Document
tts.openai.languageand that it is intended for OpenAI-compatible endpoints supportinglang_code.
This is an automated hermes-sweeper review.
| } | ||
| if speed != 1.0: | ||
| create_kwargs["speed"] = max(0.25, min(4.0, speed)) | ||
| if language: |
There was a problem hiding this comment.
Please add a regression test for this branch using the existing mocked OpenAI TTS kwargs harness in tests/tools/test_tts_speed.py: assert extra_body == {"lang_code": "es"} when configured and that it is omitted when language is unset.
Address review feedback on NousResearch#31693: - Regression tests assert extra_body == {"lang_code": ...} is forwarded when tts.openai.language is configured, and omitted when unset/empty - Document tts.openai.language as intended for OpenAI-compatible endpoints that support lang_code (e.g. Kokoro-FastAPI) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for the review — both points are addressed in f26d93d: Regression tests (
All 24 tests in the file pass locally. Docs ( |
Resolve docs conflict in tts.md (keep both the new Language section and upstream Gemini Persona Prompts / Audio Tags sections) and update the lang_code test mock for the new 3-tuple return of _resolve_openai_audio_client_config. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Address review feedback on #31693: - Regression tests assert extra_body == {"lang_code": ...} is forwarded when tts.openai.language is configured, and omitted when unset/empty - Document tts.openai.language as intended for OpenAI-compatible endpoints that support lang_code (e.g. Kokoro-FastAPI) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Merged into main via consolidated salvage PR #73513 (merge Your contribution is credited to you in git history. Thank you! Closing this PR as merged-via-salvage. |
Address review feedback on NousResearch#31693: - Regression tests assert extra_body == {"lang_code": ...} is forwarded when tts.openai.language is configured, and omitted when unset/empty - Document tts.openai.language as intended for OpenAI-compatible endpoints that support lang_code (e.g. Kokoro-FastAPI) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Address review feedback on NousResearch#31693: - Regression tests assert extra_body == {"lang_code": ...} is forwarded when tts.openai.language is configured, and omitted when unset/empty - Document tts.openai.language as intended for OpenAI-compatible endpoints that support lang_code (e.g. Kokoro-FastAPI) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Address review feedback on NousResearch#31693: - Regression tests assert extra_body == {"lang_code": ...} is forwarded when tts.openai.language is configured, and omitted when unset/empty - Document tts.openai.language as intended for OpenAI-compatible endpoints that support lang_code (e.g. Kokoro-FastAPI) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Address review feedback on NousResearch#31693: - Regression tests assert extra_body == {"lang_code": ...} is forwarded when tts.openai.language is configured, and omitted when unset/empty - Document tts.openai.language as intended for OpenAI-compatible endpoints that support lang_code (e.g. Kokoro-FastAPI) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Problem
When using Kokoro TTS (or any OpenAI-compatible TTS backend that supports
lang_code) via theopenaiprovider, thelanguagefield inconfig.yamlis ignored. The_generate_openai_tts()function readsmodel,voice,base_url, andspeedbut never passeslanguagethrough to the API.This means users configuring Kokoro for non-English languages (Spanish, French, etc.) get English phonemization — the voice reads the text with an English accent regardless of the
language: esconfig setting.Solution
Read the
languageconfig field fromtts.openai.languageand pass it asextra_body={"lang_code": language}to the OpenAI SDK'saudio.speech.create()call. The OpenAI SDK passesextra_bodyfields directly to the underlying API, which Kokoro uses to select the correct phonemizer for the target language.Changes
language = oai_config.get("language")to read the config valueextra_body={"lang_code": language}tocreate_kwargswhenlanguageis setlanguageis optional and only used when explicitly configuredConfig example
Testing
Tested against Kokoro-FastAPI with Spanish text:
af_v0sarahreads Spanish text with American English phonemizationlang_code: es