Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

feat(tts): add Kokoro TTS provider (self-hosted, OpenAI-compatible, live voice list)

Capt. Anil Sharmabd34691afe09
diff --git a/README-en.md b/README-en.md
index 7738ca4b..d1b845ac 100644
--- a/README-en.md
+++ b/README-en.md
@@ -174,7 +174,7 @@ Thanks to [Kimi](https://platform.kimi.ai?track_id=track-f6b0a640d35c41deb03b247
### Voiceover, Subtitles, and Background Music
- [x] Choose automatic voiceover, uploaded audio, or no voiceover, with voice samples and full narration previews
-- [x] Use **Edge TTS (free, no API key required)**, Azure Speech, SiliconFlow, Google Gemini, Xiaomi MiMo, MiniMax, ElevenLabs, Chatterbox, Fish Audio, and other voice services
+- [x] Use **Edge TTS (free, no API key required)**, Azure Speech, SiliconFlow, Google Gemini, Xiaomi MiMo, MiniMax, ElevenLabs, Chatterbox, Kokoro, Fish Audio, and other voice services
- [x] Generate subtitles and configure their font, position, color, size, outline, and background style
- [x] Use random, local, or AI-generated background music with independent volume control
@@ -436,7 +436,7 @@ The summary contains `total`, `succeeded`, `failed`, and `tasks`; each task entr
### Voice Synthesis
-**Azure TTS V1** in the WebUI is powered by **Edge TTS** and is free to use without an API key. MoneyPrinterTurbo also supports **Azure TTS V2**, **SiliconFlow TTS**, **Google Gemini TTS**, **Xiaomi MiMo TTS**, **ElevenLabs TTS**, self-hosted **Chatterbox TTS**, **Fish Audio TTS**, and a no-voice mode.
+**Azure TTS V1** in the WebUI is powered by **Edge TTS** and is free to use without an API key. MoneyPrinterTurbo also supports **Azure TTS V2**, **SiliconFlow TTS**, **Google Gemini TTS**, **Xiaomi MiMo TTS**, **ElevenLabs TTS**, self-hosted **Chatterbox TTS**, self-hosted **Kokoro TTS**, **Fish Audio TTS**, and a no-voice mode.
Select a provider and voice in the WebUI, then follow the on-screen instructions for any required credentials. Edge TTS does not require an API key; [Azure TTS V2](https://portal.azure.com/) and other cloud providers require credentials from their respective platforms. See the available Edge TTS voices in the [voice list](./docs/voice-list.txt).
diff --git a/README-ja.md b/README-ja.md
index 50b901a6..11e19887 100644
--- a/README-ja.md
+++ b/README-ja.md
@@ -174,7 +174,7 @@
### ナレーション・字幕・BGM
- [x] 自動ナレーション、音声ファイルのアップロード、音声なしの 3 つの方式に対応し、音声サンプルとナレーション全体をプレビュー可能
-- [x] **Edge TTS(無料・API キー不要)**、Azure Speech、SiliconFlow、Google Gemini、Xiaomi MiMo、MiniMax、ElevenLabs、Chatterbox、Fish Audio などの音声サービスに対応
+- [x] **Edge TTS(無料・API キー不要)**、Azure Speech、SiliconFlow、Google Gemini、Xiaomi MiMo、MiniMax、ElevenLabs、Chatterbox、Kokoro、Fish Audio などの音声サービスに対応
- [x] 字幕を自動生成し、フォント、位置、色、サイズ、縁取り、背景スタイルを調整可能
- [x] ランダム、ローカル、AI 生成の BGM に対応し、音量を個別に調整可能
@@ -418,7 +418,7 @@ uv run python cli.py --batch-file ./tasks.json --stop-at video
### 音声合成
-WebUI の **Azure TTS V1** は **Edge TTS** を利用しており、無料かつ API キー不要です。MoneyPrinterTurbo は **Azure TTS V2**、**SiliconFlow TTS**、**Google Gemini TTS**、**Xiaomi MiMo TTS**、**ElevenLabs TTS**、セルフホストの **Chatterbox TTS**、**Fish Audio TTS**、および音声なしモードにも対応しています。
+WebUI の **Azure TTS V1** は **Edge TTS** を利用しており、無料かつ API キー不要です。MoneyPrinterTurbo は **Azure TTS V2**、**SiliconFlow TTS**、**Google Gemini TTS**、**Xiaomi MiMo TTS**、**ElevenLabs TTS**、セルフホストの **Chatterbox TTS**、セルフホストの **Kokoro TTS**、**Fish Audio TTS**、および音声なしモードにも対応しています。
WebUI でプロバイダーと音声を選択し、必要な認証情報については画面の案内に従ってください。Edge TTS に API キーは不要です。[Azure TTS V2](https://portal.azure.com/) やその他のクラウドプロバイダーでは、それぞれのプラットフォームで発行した認証情報が必要です。利用可能な Edge TTS の音声は[音声リスト](./docs/voice-list.txt)で確認できます。
diff --git a/README.md b/README.md
index 5eb2421a..3f2335df 100644
--- a/README.md
+++ b/README.md
@@ -174,7 +174,7 @@
### 配音、字幕与配乐
- [x] 支持自动配音、上传配音和无配音三种方式,并提供音色试听与完整配音预览
-- [x] 集成 **Edge TTS(免费、无需 API Key)**、Azure Speech、SiliconFlow、Google Gemini、小米 MiMo、MiniMax、ElevenLabs、Chatterbox 和 Fish Audio 等配音服务
+- [x] 集成 **Edge TTS(免费、无需 API Key)**、Azure Speech、SiliconFlow、Google Gemini、小米 MiMo、MiniMax、ElevenLabs、Chatterbox、Kokoro 和 Fish Audio 等配音服务
- [x] 支持自动生成字幕,可调整字体、位置、颜色、大小、描边和背景样式
- [x] 支持随机、本地及 AI 生成背景音乐,并可独立控制音量
@@ -423,7 +423,7 @@ JSON 汇总。清单中的相对自定义音频与本地素材路径以清单目
### 语音合成
-WebUI 中的 **Azure TTS V1** 基于 **Edge TTS**,免费且无需 API Key。项目同时支持 **Azure TTS V2**、**SiliconFlow TTS**、**Google Gemini TTS**、**小米 MiMo TTS**、**ElevenLabs TTS**、自托管 **Chatterbox TTS**、**Fish Audio TTS**,以及无配音模式。
+WebUI 中的 **Azure TTS V1** 基于 **Edge TTS**,免费且无需 API Key。项目同时支持 **Azure TTS V2**、**SiliconFlow TTS**、**Google Gemini TTS**、**小米 MiMo TTS**、**ElevenLabs TTS**、自托管 **Chatterbox TTS**、自托管 **Kokoro TTS**、**Fish Audio TTS**,以及无配音模式。
可直接在 WebUI 中选择 Provider 和音色,并按照界面提示填写所需凭据。Edge TTS 不需要 API Key;[Azure TTS V2](https://portal.azure.com/) 及其他云端服务需要对应平台的凭据。Edge TTS 音色可查看:[音色列表](./docs/voice-list.txt)。
diff --git a/app/config/config.py b/app/config/config.py
index 1f5f19ea..d9f62ed4 100644
--- a/app/config/config.py
+++ b/app/config/config.py
@@ -497,6 +497,7 @@ def save_config():
config_to_save["minimax_tts"] = dict(minimax_tts)
config_to_save["elevenlabs"] = dict(elevenlabs)
config_to_save["chatterbox"] = dict(chatterbox)
+ config_to_save["kokoro"] = dict(kokoro)
config_to_save["fish_audio"] = dict(fish_audio)
config_to_save["ui"] = dict(ui)
serialized_config = toml.dumps(config_to_save)
@@ -553,6 +554,7 @@ siliconflow = _SynchronizedConfig(_cfg.get("siliconflow", {}))
minimax_tts = _SynchronizedConfig(_cfg.get("minimax_tts", {}))
elevenlabs = _SynchronizedConfig(_cfg.get("elevenlabs", {}))
chatterbox = _SynchronizedConfig(_cfg.get("chatterbox", {}))
+kokoro = _SynchronizedConfig(_cfg.get("kokoro", {}))
fish_audio = _SynchronizedConfig(_cfg.get("fish_audio", {}))
ui = _SynchronizedConfig(
_cfg.get(
diff --git a/app/services/voice.py b/app/services/voice.py
index 053191c7..5d2efc6d 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -221,6 +221,49 @@ def get_chatterbox_voices() -> list[str]:
return result
+KOKORO_DEFAULT_VOICE = "af_heart"
+
+
+def get_kokoro_voices() -> list[str]:
+ """Return the Kokoro voices as ``kokoro:<name>`` entries.
+
+ Operators may pin the list via ``[kokoro] voices`` (a TOML array, or a
+ comma-separated string). When it is empty the server is asked:
+ Kokoro-FastAPI and compatible servers expose ``GET {base_url}/audio/voices``
+ → ``{"voices": [...]}``. If the server cannot be reached the dropdown falls
+ back to Kokoro's default voice so the UI stays usable.
+ """
+ voices = config.kokoro.get("voices", []) or []
+ if isinstance(voices, str):
+ voices = [v.strip() for v in voices.split(",") if v.strip()]
+ voices = [str(v).strip() for v in voices if str(v).strip()]
+ if not voices:
+ base_url = (config.kokoro.get("base_url", "") or "").strip().rstrip("/")
+ if base_url:
+ try:
+ headers = {}
+ api_key = config.kokoro.get("api_key", "")
+ if api_key:
+ headers["Authorization"] = f"Bearer {api_key}"
+ response = requests.get(
+ f"{base_url}/audio/voices", headers=headers, timeout=5
+ )
+ if response.status_code == 200:
+ data = response.json()
+ listed = data.get("voices", []) if isinstance(data, dict) else data
+ voices = [str(v).strip() for v in (listed or []) if str(v).strip()]
+ else:
+ logger.warning(
+ f"kokoro voices request failed with status {response.status_code}"
+ )
+ except Exception as e:
+ logger.warning(f"kokoro voices unavailable at {base_url}: {str(e)}")
+ result = [v if v.startswith("kokoro:") else f"kokoro:{v}" for v in voices]
+ if not result:
+ result = [f"kokoro:{KOKORO_DEFAULT_VOICE}"]
+ return result
+
+
def get_fish_audio_voices() -> list[str]:
"""Return configured Fish Audio voices.
@@ -345,6 +388,10 @@ def is_chatterbox_voice(voice_name: str) -> bool:
return (voice_name or "").startswith("chatterbox:")
+def is_kokoro_voice(voice_name: str) -> bool:
+ return (voice_name or "").startswith("kokoro:")
+
+
def is_fish_audio_voice(voice_name: str) -> bool:
return (voice_name or "").startswith("fish_audio:")
@@ -544,6 +591,19 @@ def tts(
else:
logger.error(f"Invalid chatterbox voice name format: {voice_name}")
return None
+ elif is_kokoro_voice(voice_name):
+ # 格式: kokoro:<voice>,voice 可带显示用的 -Female/-Male 后缀
+ parts = voice_name.split(":", 1)
+ if len(parts) >= 2 and parts[1].strip():
+ kokoro_voice = parts[1].strip()
+ if kokoro_voice.endswith(("-Female", "-Male")):
+ kokoro_voice = kokoro_voice.rsplit("-", 1)[0]
+ return kokoro_tts(
+ text, kokoro_voice, voice_file, voice_rate, voice_volume
+ )
+ else:
+ logger.error(f"Invalid kokoro voice name format: {voice_name}")
+ return None
elif is_fish_audio_voice(voice_name):
parts = voice_name.split(":")
reference_id = parts[1] if len(parts) >= 2 else "default"
@@ -1654,43 +1714,23 @@ def elevenlabs_tts(
return None
-def chatterbox_tts(
- text: str,
+def _openai_compatible_tts(
+ provider: str,
+ base_url: str,
+ api_key: str,
+ model_id: str,
voice: str,
+ text: str,
+ voice_rate: float,
voice_file: str,
- voice_rate: float = 1.0,
- voice_volume: float = 1.0,
- model_id: str = "",
) -> Union[SubMaker, None]:
- """Generate speech with a self-hosted Chatterbox TTS server.
+ """Shared transport for self-hosted, OpenAI-compatible ``/audio/speech``
+ servers (Chatterbox, Kokoro, ...).
- Chatterbox (Resemble AI, MIT) is an open-source, locally hosted TTS model
- with zero-shot voice cloning — a self-hostable alternative to ElevenLabs.
- This talks to an OpenAI-compatible ``/audio/speech`` endpoint, so it works
- with the common community servers (e.g. devnen/Chatterbox-TTS-Server,
- travisvn/chatterbox-tts-api). Configure ``[chatterbox] base_url`` (and an
- optional ``api_key``).
-
- Like ElevenLabs, Chatterbox does not return word-level timestamps, so the
- subtitle path falls back to the full-text SubMaker. For tighter subtitle
- sync set ``subtitle_provider = "whisper"``.
+ Writes the returned audio to ``voice_file`` and builds the full-text
+ SubMaker: these servers return no word-level timestamps, so set
+ ``subtitle_provider = "whisper"`` for tighter subtitle sync.
"""
- text = (text or "").strip()
- if not text:
- logger.error("Chatterbox TTS text is empty")
- return None
-
- base_url = (config.chatterbox.get("base_url", "") or "").strip().rstrip("/")
- if not base_url:
- logger.error(
- "Chatterbox base_url is not set, please configure [chatterbox] base_url in config.toml"
- )
- return None
-
- api_key = config.chatterbox.get("api_key", "")
- if not model_id:
- model_id = config.chatterbox.get("model_id", "chatterbox") or "chatterbox"
-
url = f"{base_url}/audio/speech"
headers = {"Content-Type": "application/json"}
if api_key:
@@ -1704,20 +1744,20 @@ def chatterbox_tts(
# 1.0-centred multiplier, so it maps directly (clamped to the valid range).
"speed": max(0.25, min(4.0, float(voice_rate or 1.0))),
}
- # voice_volume is accepted for parity with the other TTS providers but is
- # intentionally not sent: the OpenAI /audio/speech contract has no volume
- # field, so Chatterbox servers ignore it. Adjust loudness via voice_rate
- # (speed) or in post-processing instead.
+ # voice_volume is accepted by the callers for parity with the other TTS
+ # providers but is intentionally not sent: the OpenAI /audio/speech contract
+ # has no volume field, so these servers ignore it. Adjust loudness via
+ # voice_rate (speed) or in post-processing instead.
for i in range(3):
try:
- logger.info(f"start chatterbox tts, voice: {voice}, try: {i + 1}")
+ logger.info(f"start {provider} tts, voice: {voice}, try: {i + 1}")
ensure_file_path_exists(voice_file)
response = requests.post(url, json=payload, headers=headers, timeout=120)
if response.status_code != 200:
logger.error(
- f"chatterbox tts failed with status {response.status_code}: {response.text[:200]}"
+ f"{provider} tts failed with status {response.status_code}: {response.text[:200]}"
)
continue
@@ -1731,18 +1771,104 @@ def chatterbox_tts(
audio_clip.close()
sub_maker = ensure_legacy_submaker_fields(SubMaker())
- logger.success(f"chatterbox tts succeeded: {voice_file}")
+ logger.success(f"{provider} tts succeeded: {voice_file}")
return populate_legacy_submaker_with_full_text(
sub_maker=sub_maker,
text=text,
audio_duration_seconds=audio_duration,
)
except Exception as e:
- logger.error(f"chatterbox tts failed: {str(e)}")
+ logger.error(f"{provider} tts failed: {str(e)}")
return None
+def chatterbox_tts(
+ text: str,
+ voice: str,
+ voice_file: str,
+ voice_rate: float = 1.0,
+ voice_volume: float = 1.0,
+ model_id: str = "",
+) -> Union[SubMaker, None]:
+ """Generate speech with a self-hosted Chatterbox TTS server.
+
+ Chatterbox (Resemble AI, MIT) is an open-source, locally hosted TTS model
+ with zero-shot voice cloning — a self-hostable alternative to ElevenLabs.
+ This talks to an OpenAI-compatible ``/audio/speech`` endpoint, so it works
+ with the common community servers (e.g. devnen/Chatterbox-TTS-Server,
+ travisvn/chatterbox-tts-api). Configure ``[chatterbox] base_url`` (and an
+ optional ``api_key``).
+
+ Like ElevenLabs, Chatterbox does not return word-level timestamps, so the
+ subtitle path falls back to the full-text SubMaker. For tighter subtitle
+ sync set ``subtitle_provider = "whisper"``.
+ """
+ text = (text or "").strip()
+ if not text:
+ logger.error("Chatterbox TTS text is empty")
+ return None
+
+ base_url = (config.chatterbox.get("base_url", "") or "").strip().rstrip("/")
+ if not base_url:
+ logger.error(
+ "Chatterbox base_url is not set, please configure [chatterbox] base_url in config.toml"
+ )
+ return None
+
+ api_key = config.chatterbox.get("api_key", "")
+ if not model_id:
+ model_id = config.chatterbox.get("model_id", "chatterbox") or "chatterbox"
+
+ return _openai_compatible_tts(
+ "chatterbox", base_url, api_key, model_id, voice, text, voice_rate, voice_file
+ )
+
+
+def kokoro_tts(
+ text: str,
+ voice: str,
+ voice_file: str,
+ voice_rate: float = 1.0,
+ voice_volume: float = 1.0,
+ model_id: str = "",
+) -> Union[SubMaker, None]:
+ """Generate speech with a self-hosted Kokoro TTS server.
+
+ Kokoro (hexgrad/Kokoro-82M, Apache-2.0 code and weights) is a small open
+ TTS model that runs well on CPU — a free, offline alternative to the
+ cloud voices. This talks to an OpenAI-compatible ``/audio/speech``
+ endpoint, so it works with the common servers (e.g. remsky/Kokoro-FastAPI
+ on port 8880). Configure ``[kokoro] base_url`` (ending in ``/v1``) and an
+ optional ``api_key``.
+
+ Voice names are Kokoro's presets (``af_heart``, ``bf_emma``, ``hf_alpha``,
+ ...); their first letter is the language (a/b English, e Spanish, f French,
+ h Hindi, i Italian, p Portuguese, j Japanese, z Chinese), so pick a voice
+ that matches the script's language.
+
+ Like Chatterbox, the OpenAI speech contract returns no word-level
+ timestamps, so the subtitle path falls back to the full-text SubMaker.
+ For tighter subtitle sync set ``subtitle_provider = "whisper"``.
+ """
+ text = (text or "").strip()
+ if not text:
+ logger.error("Kokoro TTS text is empty")
+ return None
+ base_url = (config.kokoro.get("base_url", "") or "").strip().rstrip("/")
+ if not base_url:
+ logger.error(
+ "Kokoro base_url is not set, please configure [kokoro] base_url in config.toml"
+ )
+ return None
+ api_key = config.kokoro.get("api_key", "")
+ if not model_id:
+ model_id = config.kokoro.get("model_id", "kokoro") or "kokoro"
+ return _openai_compatible_tts(
+ "kokoro", base_url, api_key, model_id, voice, text, voice_rate, voice_file
+ )
+
+
# Fish Audio supported models.
FISH_AUDIO_MODELS = ("s2.1-pro-free", "s2.1-pro", "s2-pro")
FISH_AUDIO_DEFAULT_MODEL = "s2.1-pro-free"
diff --git a/cli.py b/cli.py
index 75fca142..6d44f363 100644
--- a/cli.py
+++ b/cli.py
@@ -390,7 +390,7 @@ Batch manifests:
"[ui].voice_mode of 'none' or 'upload' resolves to no-voice "
"instead, unless this option is given. "
"Use 'no-voice' for silent output. Provider-specific identifiers "
- "use prefixes such as gemini:, mimo:, elevenlabs:, and chatterbox:"
+ "use prefixes such as gemini:, mimo:, elevenlabs:, and chatterbox:""use prefixes such as gemini:, mimo:, elevenlabs:, chatterbox:, and kokoro:"
),
)
audio_group.add_argument(
diff --git a/config.example.toml b/config.example.toml
index 5255e0a4..72ce4e8f 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -534,6 +534,16 @@ model_id = "chatterbox"
# Voice names exposed by the configured Chatterbox server.
voices = ["default-Female"]
+[kokoro]
+# OpenAI-compatible Kokoro TTS server (hexgrad/Kokoro-82M, Apache-2.0, runs on CPU).
+# The defaults target remsky/Kokoro-FastAPI running locally on port 8880.
+base_url = "http://127.0.0.1:8880/v1"
+api_key = ""
+model_id = "kokoro"
+# Voice names (af_heart, bf_emma, hf_alpha, ...). Leave empty to read the list
+# from the server (GET {base_url}/audio/voices).
+voices = []
+
[fish_audio]
# Fish Audio TTS service: https://fish.audio
# API key: https://fish.audio/app/developers
diff --git a/webui/Main.py b/webui/Main.py
index 03aec274..93704f28 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -97,6 +97,10 @@ locales = utils.load_locales(i18n_dir)
DEFAULT_CHATTERBOX_BASE_URL = "http://127.0.0.1:4123/v1"
DEFAULT_CHATTERBOX_MODEL = "chatterbox"
DEFAULT_CHATTERBOX_VOICES = ["default-Female"]
+DEFAULT_KOKORO_BASE_URL = "http://127.0.0.1:8880/v1"
+DEFAULT_KOKORO_MODEL = "kokoro"
+# empty = ask the server for its voice list (GET {base_url}/audio/voices)
+DEFAULT_KOKORO_VOICES: list[str] = []
ONBOARDING_TOUR_KEY = "mpt-onboarding-v1"
CUSTOM_LLM_ENDPOINT_ID = "custom"
VOICE_MODE_TTS = "tts"
@@ -178,6 +182,7 @@ _RUNTIME_CONFIG_SECTIONS = {
"app": config.app,
"azure": config.azure,
"chatterbox": config.chatterbox,
+ "kokoro": config.kokoro,
"elevenlabs": config.elevenlabs,
"minimax_tts": config.minimax_tts,
"siliconflow": config.siliconflow,
@@ -428,6 +433,53 @@ def _sync_chatterbox_config_from_session_state():
)
+def _sync_kokoro_config_from_session_state():
+ # 与 Chatterbox 相同:Kokoro 配置输入框位于试听按钮之后,先从 session_state 同步一次。
+ # Streamlit 的按钮会触发整页 rerun,而 Kokoro 配置输入框位于
+ # “试听语音合成”按钮之后。如果试听时只读取 config.kokoro,可能拿不到
+ # 用户刚在输入框里填入的 base_url/model/voices。先从 session_state 同步一次,
+ # 可以保证按钮逻辑和输入框显示逻辑使用同一份最新配置。
+ _set_runtime_config(
+ "kokoro",
+ "base_url",
+ (
+ st.session_state.get(
+ "kokoro_base_url_input",
+ config.kokoro.get("base_url") or DEFAULT_KOKORO_BASE_URL,
+ )
+ or ""
+ ).strip(),
+ )
+ _set_runtime_config(
+ "kokoro",
+ "api_key",
+ st.session_state.get(
+ "kokoro_api_key_input", config.kokoro.get("api_key", "")
+ ),
+ )
+ _set_runtime_config(
+ "kokoro",
+ "model_id",
+ (
+ st.session_state.get(
+ "kokoro_model_input",
+ config.kokoro.get("model_id") or DEFAULT_KOKORO_MODEL,
+ )
+ or DEFAULT_KOKORO_MODEL
+ ).strip(),
+ )
+ _set_runtime_config(
+ "kokoro",
+ "voices",
+ _parse_chatterbox_voices(
+ st.session_state.get(
+ "kokoro_voices_input",
+ config.kokoro.get("voices") or DEFAULT_KOKORO_VOICES,
+ )
+ ),
+ )
+
+
def _detect_audio_mime(audio_file: str, audio_bytes: bytes) -> str:
# 有些 OpenAI-compatible TTS 服务,例如 travisvn/chatterbox-tts-api,
# 即使请求 response_format=mp3,也会返回 WAV 内容。WebUI 试听如果固定
@@ -1270,6 +1322,8 @@ def _infer_tts_server_from_voice(voice_name):
return "elevenlabs"
if voice.is_chatterbox_voice(voice_name):
return "chatterbox"
+ if voice.is_kokoro_voice(voice_name):
+ return "kokoro"
if voice.is_fish_audio_voice(voice_name):
return "fish_audio"
if voice.is_azure_v2_voice(voice_name):
@@ -4994,6 +5048,12 @@ def _get_voice_preview_provider_signature(tts_server: str) -> dict:
"model_id": config.chatterbox.get("model_id", ""),
"credential": _credential_signature(config.chatterbox.get("api_key", "")),
}
+ if tts_server == "kokoro":
+ return {
+ "base_url": config.kokoro.get("base_url", ""),
+ "model_id": config.kokoro.get("model_id", ""),
+ "credential": _credential_signature(config.kokoro.get("api_key", "")),
+ }
return {}
@@ -5009,6 +5069,8 @@ def _synthesize_voice_preview(
"""生成一次试听并转为内存缓存,临时文件不会跨会话长期保留。"""
if selected_tts_server == "chatterbox":
_sync_chatterbox_config_from_session_state()
+ if selected_tts_server == "kokoro":
+ _sync_kokoro_config_from_session_state()
temp_dir = utils.storage_dir("temp", create=True)
audio_file = os.path.join(temp_dir, f"tmp-voice-{str(uuid4())}.mp3")
@@ -5814,6 +5876,7 @@ def _render_audio_settings(panel, params):
("minimax-tts", "MiniMax TTS"),
("elevenlabs", "ElevenLabs TTS"),
("chatterbox", "Chatterbox TTS"),
+ ("kokoro", "Kokoro TTS"),
("fish_audio", "Fish Audio TTS"),
]
@@ -5884,6 +5947,10 @@ def _render_audio_settings(panel, params):
# 自托管 Chatterbox 服务的预置音色(来自 [chatterbox] voices 配置)
_sync_chatterbox_config_from_session_state()
filtered_voices = voice.get_chatterbox_voices()
+ elif selected_tts_server == "kokoro":
+ # 自托管 Kokoro 服务的音色:[kokoro] voices 为空时从服务端 /audio/voices 读取
+ _sync_kokoro_config_from_session_state()
+ filtered_voices = voice.get_kokoro_voices()
elif selected_tts_server == "fish_audio":
filtered_voices = voice.get_fish_audio_voices()
else:
@@ -6193,6 +6260,59 @@ def _render_audio_settings(panel, params):
_parse_chatterbox_voices(chatterbox_voices),
)
+ # Kokoro API settings section (self-hosted, OpenAI-compatible; voices listed from the server when left empty)
+ if tts_mode_enabled and (
+ selected_tts_server == "kokoro"
+ or (voice_name and voice.is_kokoro_voice(voice_name))
+ ):
+ kokoro_base_url = st.text_input(
+ tr("Kokoro Base URL"),
+ value=config.kokoro.get("base_url")
+ or DEFAULT_KOKORO_BASE_URL,
+ key="kokoro_base_url_input",
+ placeholder=tr("Kokoro Base URL Placeholder"),
+ )
+ _set_runtime_config(
+ "kokoro", "base_url", (kokoro_base_url or "").strip()
+ )
+
+ kokoro_api_key = st.text_input(
+ tr("Kokoro API Key"),
+ value=config.kokoro.get("api_key", ""),
+ type="password",
+ key="kokoro_api_key_input",
+ )
+ _set_runtime_config("kokoro", "api_key", kokoro_api_key)
+
+ kokoro_model = st.text_input(
+ tr("Kokoro Model"),
+ value=config.kokoro.get("model_id") or DEFAULT_KOKORO_MODEL,
+ key="kokoro_model_input",
+ )
+ _set_runtime_config(
+ "kokoro",
+ "model_id",
+ (kokoro_model or DEFAULT_KOKORO_MODEL).strip(),
+ )
+
+ _saved_kokoro_voices = (
+ _parse_chatterbox_voices(config.kokoro.get("voices"))
+ or DEFAULT_KOKORO_VOICES
+ )
+ if isinstance(_saved_kokoro_voices, list):
+ _saved_kokoro_voices = ", ".join(_saved_kokoro_voices)
+ kokoro_voices = st.text_input(
+ tr("Kokoro Voices"),
+ value=str(_saved_kokoro_voices or ""),
+ key="kokoro_voices_input",
+ placeholder=tr("Kokoro Voices Placeholder"),
+ )
+ _set_runtime_config(
+ "kokoro",
+ "voices",
+ _parse_chatterbox_voices(kokoro_voices),
+ )
+
# 三种模式只渲染当前任务真正需要的控件。自动配音可调音量和语速;
# 上传音频只需要文件和音量;无配音不再展示无效设置。
params.voice_name = (
diff --git a/webui/i18n/en.json b/webui/i18n/en.json
index 6af172eb..321bf23b 100644
--- a/webui/i18n/en.json
+++ b/webui/i18n/en.json
@@ -276,6 +276,12 @@
"Chatterbox Voices": "Chatterbox Voices",
"Chatterbox Base URL Placeholder": "http://localhost:4123/v1",
"Chatterbox Voices Placeholder": "default-Female, narrator-Male",
+ "Kokoro Base URL": "Kokoro Base URL",
+ "Kokoro API Key": "Kokoro API Key (Optional; [View Setup](https://github.com/remsky/Kokoro-FastAPI))",
+ "Kokoro Model": "Kokoro Model",
+ "Kokoro Voices": "Kokoro Voices",
+ "Kokoro Base URL Placeholder": "http://localhost:8880/v1",
+ "Kokoro Voices Placeholder": "leave empty to list the server's voices, or e.g. af_heart, bf_emma, hf_alpha",
"tts_provider_tips.azure-tts-v2": "Requires an Azure Speech **region** and **API key**. Create or view them in the [Azure Portal](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/SpeechServices).",
"tts_provider_tips.siliconflow": "Requires a SiliconFlow API key from the [console](https://cloud.siliconflow.cn/account/ak). Numeric speed and volume gain are supported.",
"tts_provider_tips.gemini-tts": "Requires a Gemini API key from [Google AI Studio](https://aistudio.google.com/app/apikey). [Preview all supported voices](https://aistudio.google.com/generate-speech) in Google's Voice Library. Pace and style are controlled through natural-language instructions.",
@@ -283,6 +289,7 @@
"tts_provider_tips.minimax-tts": "Use a MiniMax TTS API key from the [China platform](https://platform.minimaxi.com/user-center/basic-information/interface-key) or [global platform](https://platform.minimax.io/user-center/basic-information/interface-key). The key and endpoint must belong to the same platform. If left empty, the MiniMax LLM key and its matching endpoint are reused.",
"tts_provider_tips.elevenlabs": "Requires an [API key](https://elevenlabs.io/app/settings/api-keys). Add voices to your favorites in the [Voice Library](https://elevenlabs.io/app/voice-library) first.",
"tts_provider_tips.chatterbox": "Self-hosted. Run a compatible [Chatterbox TTS API](https://github.com/travisvn/chatterbox-tts-api), then enter a Base URL ending in `/v1`; the API key is usually optional.",
+ "tts_provider_tips.kokoro": "Self-hosted and free: run a compatible [Kokoro-FastAPI](https://github.com/remsky/Kokoro-FastAPI) server (Apache-2.0 model, CPU is enough), then enter a Base URL ending in `/v1`; the voice list is read from the server.",
"tts_provider_tips.fish_audio": "Requires a Fish Audio API key from the [developer portal](https://fish.audio/app/developers). [Browse public voices](https://fish.audio) or configure custom voices in `config.toml`. See [pricing & terms](https://fish.audio/pricing).",
"Hide Log": "Hide Log",
"Hide Basic Settings": "Hide Basic Settings\n\nHidden, the basic settings panel will not be displayed on the page.\n\nIf you need to display it again, please set `hide_config = false` in `config.toml`",
diff --git a/webui/i18n/zh.json b/webui/i18n/zh.json
index 0af3ed4f..67e1045a 100644
--- a/webui/i18n/zh.json
+++ b/webui/i18n/zh.json
@@ -276,6 +276,12 @@
"Chatterbox Voices": "Chatterbox 音色",
"Chatterbox Base URL Placeholder": "http://localhost:4123/v1",
"Chatterbox Voices Placeholder": "default-Female, narrator-Male",
+ "Kokoro Base URL": "Kokoro Base URL",
+ "Kokoro API Key": "Kokoro API 密钥(可选,[查看配置](https://github.com/remsky/Kokoro-FastAPI))",
+ "Kokoro Model": "Kokoro 模型",
+ "Kokoro Voices": "Kokoro 音色",
+ "Kokoro Base URL Placeholder": "http://localhost:8880/v1",
+ "Kokoro Voices Placeholder": "留空则自动读取服务端音色列表,或填写 af_heart, bf_emma, hf_alpha",
"tts_provider_tips.azure-tts-v2": "需要 Azure Speech 的 **区域**和 **API Key**。可在 [Azure Portal](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/SpeechServices) 创建和查看。",
"tts_provider_tips.siliconflow": "需要硅基流动 API Key,可在[控制台](https://cloud.siliconflow.cn/account/ak)创建;支持数值语速和音量增益。",
"tts_provider_tips.gemini-tts": "需要 Gemini API Key,可在 [Google AI Studio](https://aistudio.google.com/app/apikey) 创建;可在 Google 的[音色库](https://aistudio.google.com/generate-speech)试听全部支持的音色;语速和风格由模型根据自然语言提示控制。",
@@ -283,6 +289,7 @@
"tts_provider_tips.minimax-tts": "使用 [MiniMax 中国站](https://platform.minimaxi.com/user-center/basic-information/interface-key)或[国际站](https://platform.minimax.io/user-center/basic-information/interface-key)的 TTS API Key,Key 与服务地址必须属于同一站点。留空时会复用 MiniMax 大模型 Key,并自动匹配对应站点。",
"tts_provider_tips.elevenlabs": "需要 [API Key](https://elevenlabs.io/app/settings/api-keys);请先在 [Voice Library](https://elevenlabs.io/app/voice-library) 将音色加入收藏。",
"tts_provider_tips.chatterbox": "自托管服务。运行兼容的 [Chatterbox TTS API](https://github.com/travisvn/chatterbox-tts-api),并填写以 `/v1` 结尾的 Base URL;API Key 通常可选。",
+ "tts_provider_tips.kokoro": "自托管、免费:运行兼容的 [Kokoro-FastAPI](https://github.com/remsky/Kokoro-FastAPI)(Apache-2.0 模型,CPU 即可),并填写以 `/v1` 结尾的 Base URL;音色列表自动从服务端读取。",
"tts_provider_tips.fish_audio": "需要 Fish Audio API Key,可在[开发者控制台](https://fish.audio/app/developers)获取;可在 [Fish Audio](https://fish.audio) 浏览更多音色或在 `config.toml` 中配置自定义音色;查看[价格与条款](https://fish.audio/pricing)。",
"Hide Log": "隐藏日志",
"Hide Basic Settings": "隐藏基础设置\n\n隐藏后,基础设置面板将不会显示在页面中。\n\n如需要再次显示,请在 `config.toml` 中设置 `hide_config = false`",