Skip to content

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

Update Gemini TTS voice catalog

Ding Zhaoxiong 丁肇雄89fe95302cd1
diff --git a/app/services/voice.py b/app/services/voice.py
index 05dc0d29..85f66243 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -39,6 +39,38 @@ MINIMAX_TTS_MODELS = (
"speech-2.8-hd", "speech-2.8-turbo", "speech-2.6-hd", "speech-2.6-turbo",
"speech-02-hd", "speech-02-turbo", "speech-01-hd", "speech-01-turbo",
)
+GEMINI_TTS_VOICES = (
+ ("Zephyr", "Bright"),
+ ("Puck", "Upbeat"),
+ ("Charon", "Informative"),
+ ("Kore", "Firm"),
+ ("Fenrir", "Excitable"),
+ ("Leda", "Youthful"),
+ ("Orus", "Firm"),
+ ("Aoede", "Breezy"),
+ ("Callirrhoe", "Easy-going"),
+ ("Autonoe", "Bright"),
+ ("Enceladus", "Breathy"),
+ ("Iapetus", "Clear"),
+ ("Umbriel", "Easy-going"),
+ ("Algieba", "Smooth"),
+ ("Despina", "Smooth"),
+ ("Erinome", "Clear"),
+ ("Algenib", "Gravelly"),
+ ("Rasalgethi", "Informative"),
+ ("Laomedeia", "Upbeat"),
+ ("Achernar", "Soft"),
+ ("Alnilam", "Firm"),
+ ("Schedar", "Even"),
+ ("Gacrux", "Mature"),
+ ("Pulcherrima", "Forward"),
+ ("Achird", "Friendly"),
+ ("Zubenelgenubi", "Casual"),
+ ("Vindemiatrix", "Gentle"),
+ ("Sadachbia", "Lively"),
+ ("Sadaltager", "Knowledgeable"),
+ ("Sulafat", "Warm"),
+)
_MINIMAX_TTS_MAX_AUDIO_HEX_CHARS = 100 * 1024 * 1024
NO_VOICE_NAME = "no-voice"
# `none` 是 PR #981 里曾使用过的无配音标识。这里短期兼容这个值,避免
@@ -95,35 +127,16 @@ def get_siliconflow_voices() -> list[str]:
def get_gemini_voices() -> list[str]:
"""
- 获取Gemini TTS的声音列表
-
+ 获取 Gemini TTS 官方预置音色列表。
+
+ Google 没有为这些音色发布性别元数据,因此下拉框使用官方风格描述,
+ 避免把推测的性别写进持久化 voice id。音色目录来源:
+ https://ai.google.dev/gemini-api/docs/speech-generation#voice-options
+
Returns:
- 声音列表,格式为 ["gemini:Zephyr-Female", "gemini:Puck-Male", ...]
+ 声音列表,格式为 ["gemini:Zephyr-Bright", "gemini:Puck-Upbeat", ...]
"""
- # Gemini TTS支持的语音列表
- voices_with_gender = [
- ("Zephyr", "Female"),
- ("Puck", "Male"),
- ("Charon", "Male"),
- ("Kore", "Female"),
- ("Fenrir", "Male"),
- ("Aoede", "Female"),
- ("Thalia", "Female"),
- ("Sage", "Male"),
- ("Echo", "Female"),
- ("Harmony", "Female"),
- ("Lux", "Female"),
- ("Nova", "Female"),
- ("Vale", "Male"),
- ("Orion", "Male"),
- ("Atlas", "Male"),
- ]
-
- # 添加gemini:前缀,并格式化为显示名称
- return [
- f"gemini:{voice}-{gender}"
- for voice, gender in voices_with_gender
- ]
+ return [f"gemini:{voice}-{style}" for voice, style in GEMINI_TTS_VOICES]
def get_mimo_voices() -> list[str]:
@@ -264,6 +277,13 @@ def is_gemini_voice(voice_name: str):
return voice_name.startswith("gemini:")
+def parse_gemini_voice_name(voice_name: str | None) -> str:
+ """从新旧 Gemini 下拉框值中提取 Google API 使用的预置音色名称。"""
+ if not is_gemini_voice(voice_name or ""):
+ return ""
+ return (voice_name or "").split(":", 1)[1].split("-", 1)[0].strip()
+
+
def is_mimo_voice(voice_name: str):
"""检查是否是 Xiaomi MiMo TTS 的声音"""
return voice_name.startswith("mimo:")
@@ -436,12 +456,9 @@ def tts(
return None
elif is_gemini_voice(voice_name):
# 从voice_name中提取声音名称
- # 格式: gemini:voice-Gender
- parts = voice_name.split(":")
- if len(parts) >= 2:
- # 移除性别后缀,例如 "Zephyr-Female" -> "Zephyr"
- voice_with_gender = parts[1]
- voice = voice_with_gender.split("-")[0]
+ # 格式: gemini:voice-Style;也继续兼容旧的 gemini:voice-Gender。
+ voice = parse_gemini_voice_name(voice_name)
+ if voice:
return gemini_tts(text, voice, voice_rate, voice_file, voice_volume)
else:
logger.error(f"Invalid gemini voice name format: {voice_name}")
diff --git a/test/services/test_voice.py b/test/services/test_voice.py
index 27bdf375..96cbdd68 100644
--- a/test/services/test_voice.py
+++ b/test/services/test_voice.py
@@ -68,6 +68,33 @@ class TestVoiceService(unittest.TestCase):
all(v.startswith(("zh-CN", "en-US")) for v in filtered)
)
+ def test_get_gemini_voices_matches_documented_catalog(self):
+ voices = vs.get_gemini_voices()
+
+ self.assertEqual(len(voices), 30)
+ self.assertEqual(
+ [name for name, _style in vs.GEMINI_TTS_VOICES],
+ [
+ "Zephyr", "Puck", "Charon", "Kore", "Fenrir", "Leda",
+ "Orus", "Aoede", "Callirrhoe", "Autonoe", "Enceladus",
+ "Iapetus", "Umbriel", "Algieba", "Despina", "Erinome",
+ "Algenib", "Rasalgethi", "Laomedeia", "Achernar", "Alnilam",
+ "Schedar", "Gacrux", "Pulcherrima", "Achird",
+ "Zubenelgenubi", "Vindemiatrix", "Sadachbia", "Sadaltager",
+ "Sulafat",
+ ],
+ )
+ self.assertIn("gemini:Achernar-Soft", voices)
+ self.assertIn("gemini:Sulafat-Warm", voices)
+ self.assertFalse(any("Atlas" in voice for voice in voices))
+
+ def test_parse_gemini_voice_name_supports_new_and_legacy_labels(self):
+ self.assertEqual(
+ vs.parse_gemini_voice_name("gemini:Achernar-Soft"), "Achernar"
+ )
+ self.assertEqual(vs.parse_gemini_voice_name("gemini:Charon-Male"), "Charon")
+ self.assertEqual(vs.parse_gemini_voice_name("Charon-Male"), "")
+
def test_no_voice_tts_generates_silent_audio_and_subtitle_timeline(self):
"""
无配音模式不调用任何外部 TTS provider,只生成静音音频作为时间轴占位。
@@ -398,6 +425,28 @@ class TestVoiceService(unittest.TestCase):
voice_rate=1.8,
)
+ def test_tts_strips_gemini_style_metadata_before_dispatch(self):
+ """Gemini 下拉框的官方风格描述不能成为 API voice_name 的一部分。"""
+ sentinel = object()
+
+ with patch.object(vs, "gemini_tts", return_value=sentinel) as gemini_tts:
+ result = vs.tts(
+ text="Test the updated voice catalog.",
+ voice_name="gemini:Achernar-Soft",
+ voice_rate=1.0,
+ voice_file="/tmp/gemini-achernar.mp3",
+ voice_volume=1.0,
+ )
+
+ self.assertIs(result, sentinel)
+ gemini_tts.assert_called_once_with(
+ "Test the updated voice catalog.",
+ "Achernar",
+ 1.0,
+ "/tmp/gemini-achernar.mp3",
+ 1.0,
+ )
+
def test_gemini_tts_uses_google_genai_and_compatible_submaker_fields(self):
"""
验证 Gemini TTS 在 edge_tts 7.x 环境下仍会返回项目兼容的字幕结构,
diff --git a/webui/Main.py b/webui/Main.py
index a1287f26..1f06489a 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -4323,6 +4323,23 @@ def _render_audio_settings(panel, params):
friendly_names = {v: _friendly(v) for v in filtered_voices}
+ # Gemini 旧目录把推测的性别放在值里(例如 Charon-Male)。按基础
+ # voice name 映射到新的官方风格值,升级后继续保留用户原来的音色。
+ if (
+ selected_tts_server == "gemini-tts"
+ and saved_voice_name not in friendly_names
+ ):
+ saved_gemini_voice = voice.parse_gemini_voice_name(saved_voice_name)
+ saved_voice_name = next(
+ (
+ candidate
+ for candidate in filtered_voices
+ if voice.parse_gemini_voice_name(candidate)
+ == saved_gemini_voice
+ ),
+ saved_voice_name,
+ )
+
saved_voice_name_index = 0
# 检查保存的声音是否在当前筛选的声音列表中
diff --git a/webui/i18n/en.json b/webui/i18n/en.json
index d4ad5e99..f4c2cfc4 100644
--- a/webui/i18n/en.json
+++ b/webui/i18n/en.json
@@ -256,7 +256,7 @@
"Chatterbox Voices Placeholder": "default-Female, narrator-Male",
"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). Pace and style are controlled through natural-language instructions.",
+ "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.",
"tts_provider_tips.mimo-tts": "Requires a Xiaomi MiMo API key; see the [first API call](https://mimo.mi.com/docs/quick-start/first-api-call). MiMo V2.5 controls pace and style through natural-language instructions.",
"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.",
diff --git a/webui/i18n/zh.json b/webui/i18n/zh.json
index df2a0fce..0fdfa27c 100644
--- a/webui/i18n/zh.json
+++ b/webui/i18n/zh.json
@@ -256,7 +256,7 @@
"Chatterbox Voices Placeholder": "default-Female, narrator-Male",
"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) 创建;语速和风格由模型根据自然语言提示控制。",
+ "tts_provider_tips.gemini-tts": "需要 Gemini API Key,可在 [Google AI Studio](https://aistudio.google.com/app/apikey) 创建;可在 Google 的[音色库](https://aistudio.google.com/generate-speech)试听全部支持的音色;语速和风格由模型根据自然语言提示控制。",
"tts_provider_tips.mimo-tts": "需要小米 MiMo API Key,参考[首次调用](https://mimo.mi.com/docs/zh-CN/quick-start/first-api-call);V2.5 TTS 通过自然语言指令控制语速和风格。",
"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) 将音色加入收藏。",