利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
Add Chatterbox WebUI settings, provider tests, and clarify voice_volume
Paulo C. Benetti815e9ce30492
diff --git a/app/services/voice.py b/app/services/voice.pyindex 190fa546..1d8072f0 100644--- a/app/services/voice.py+++ b/app/services/voice.py@@ -1359,6 +1359,10 @@ 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.for i in range(3):try:diff --git a/test/services/test_voice.py b/test/services/test_voice.pyindex c4b5f58c..57128114 100644--- a/test/services/test_voice.py+++ b/test/services/test_voice.py@@ -504,6 +504,127 @@ class TestVoiceService(unittest.TestCase):self.assertEqual(getattr(sub_maker, "subs", []), ["小米语音合成测试", "第二句话"])self.assertEqual(len(getattr(sub_maker, "offset", [])), 2)+ def test_chatterbox_voice_helpers(self):+ """is_chatterbox_voice / get_chatterbox_voices basics and normalisation."""+ self.assertTrue(vs.is_chatterbox_voice("chatterbox:default-Female"))+ self.assertFalse(vs.is_chatterbox_voice("elevenlabs:abc:Rachel"))+ self.assertFalse(vs.is_chatterbox_voice(""))+ self.assertFalse(vs.is_chatterbox_voice(None))++ # list entries are normalised to the chatterbox:<name> dispatcher format,+ # and entries that are already prefixed are left untouched+ with patch.object(+ vs.config,+ "chatterbox",+ {"voices": ["narrator-Male", "chatterbox:host"]},+ ):+ self.assertEqual(+ vs.get_chatterbox_voices(),+ ["chatterbox:narrator-Male", "chatterbox:host"],+ )++ # a comma-separated string is also accepted (TOML-friendly)+ with patch.object(vs.config, "chatterbox", {"voices": "alpha, beta ,"}):+ self.assertEqual(+ vs.get_chatterbox_voices(),+ ["chatterbox:alpha", "chatterbox:beta"],+ )++ # with nothing configured the dropdown still gets a usable default+ with patch.object(vs.config, "chatterbox", {}):+ self.assertEqual(vs.get_chatterbox_voices(), ["chatterbox:default-Female"])++ def test_chatterbox_tts_posts_to_openai_compatible_endpoint(self):+ """Success path: POST /audio/speech, write audio, return legacy SubMaker."""++ class _FakeResponse:+ status_code = 200+ content = b"RIFF-fake-wav"+ text = ""++ class _FakeClip:+ duration = 3.5++ def close(self):+ pass++ captured = {}++ def _fake_post(url, json=None, headers=None, timeout=None):+ captured["url"] = url+ captured["json"] = json+ captured["headers"] = headers+ return _FakeResponse()++ with tempfile.TemporaryDirectory() as tmp_dir, patch.object(+ vs.config,+ "chatterbox",+ {+ "base_url": "http://localhost:4123/v1/",+ "api_key": "secret",+ "model_id": "chatterbox",+ },+ ), patch.object(+ vs.requests, "post", side_effect=_fake_post+ ) as post, patch.object(+ vs, "AudioFileClip", return_value=_FakeClip()+ ):+ voice_file = str(Path(tmp_dir) / "chatterbox.mp3")+ sub_maker = vs.chatterbox_tts(+ text="Hello world. Second sentence.",+ voice="default",+ voice_file=voice_file,+ voice_rate=1.2,+ voice_volume=1.0,+ )+ generated_audio = Path(voice_file).read_bytes()++ post.assert_called_once()+ # trailing slash on base_url is stripped before appending /audio/speech+ self.assertEqual(captured["url"], "http://localhost:4123/v1/audio/speech")+ self.assertEqual(captured["json"]["model"], "chatterbox")+ self.assertEqual(captured["json"]["voice"], "default")+ self.assertEqual(captured["json"]["input"], "Hello world. Second sentence.")+ self.assertAlmostEqual(captured["json"]["speed"], 1.2)+ # api_key is forwarded as a bearer token+ self.assertEqual(captured["headers"].get("Authorization"), "Bearer secret")+ # volume is intentionally not part of the OpenAI speech payload+ self.assertNotIn("volume", captured["json"])+ self.assertEqual(generated_audio, b"RIFF-fake-wav")+ self.assertIsNotNone(sub_maker)+ self.assertTrue(getattr(sub_maker, "subs", []))++ def test_chatterbox_tts_requires_base_url(self):+ """Missing base_url short-circuits without any network call."""+ with patch.object(+ vs.config, "chatterbox", {"base_url": ""}+ ), patch.object(vs.requests, "post") as post:+ result = vs.chatterbox_tts(+ text="hi", voice="default", voice_file="unused.mp3"+ )+ self.assertIsNone(result)+ post.assert_not_called()++ def test_chatterbox_tts_returns_none_on_http_error(self):+ """A non-200 response is retried up to 3 times, then fails to None."""++ class _FakeResponse:+ status_code = 500+ content = b""+ text = "boom"++ with tempfile.TemporaryDirectory() as tmp_dir, patch.object(+ vs.config, "chatterbox", {"base_url": "http://localhost:4123/v1"}+ ), patch.object(+ vs.requests, "post", return_value=_FakeResponse()+ ) as post:+ voice_file = str(Path(tmp_dir) / "chatterbox.mp3")+ result = vs.chatterbox_tts(+ text="hi", voice="default", voice_file=voice_file+ )+ self.assertIsNone(result)+ self.assertEqual(post.call_count, 3)+def test_generate_subtitle_keeps_edge_provider_for_gemini_legacy_submaker(self):"""验证 Gemini TTS 返回的 legacy 字幕结构在 edge provider 下可以直接产出diff --git a/webui/Main.py b/webui/Main.pyindex cddc26d1..850c8a32 100644--- a/webui/Main.py+++ b/webui/Main.py@@ -1259,6 +1259,58 @@ with middle_panel:config.elevenlabs["api_key"] = elevenlabs_api_key+ # Chatterbox API settings section (self-hosted, OpenAI-compatible)+ if selected_tts_server == "chatterbox" or (+ voice_name and voice.is_chatterbox_voice(voice_name)+ ):+ chatterbox_base_url = st.text_input(+ tr("Chatterbox Base URL"),+ value=config.chatterbox.get("base_url", ""),+ key="chatterbox_base_url_input",+ placeholder="http://localhost:4123/v1",+ )+ config.chatterbox["base_url"] = (chatterbox_base_url or "").strip()++ chatterbox_api_key = st.text_input(+ tr("Chatterbox API Key"),+ value=config.chatterbox.get("api_key", ""),+ type="password",+ key="chatterbox_api_key_input",+ )+ config.chatterbox["api_key"] = chatterbox_api_key++ chatterbox_model = st.text_input(+ tr("Chatterbox Model"),+ value=config.chatterbox.get("model_id", "chatterbox") or "chatterbox",+ key="chatterbox_model_input",+ )+ config.chatterbox["model_id"] = (chatterbox_model or "chatterbox").strip()++ _saved_chatterbox_voices = config.chatterbox.get("voices", [])+ if isinstance(_saved_chatterbox_voices, list):+ _saved_chatterbox_voices = ", ".join(_saved_chatterbox_voices)+ chatterbox_voices = st.text_input(+ tr("Chatterbox Voices"),+ value=str(_saved_chatterbox_voices or ""),+ key="chatterbox_voices_input",+ placeholder="default-Female, narrator-Male",+ )+ config.chatterbox["voices"] = [+ v.strip() for v in chatterbox_voices.split(",") if v.strip()+ ]++ st.info(+ "Chatterbox TTS Settings (self-hosted):\n"+ "- Run an OpenAI-compatible Chatterbox server (e.g. "+ "devnen/Chatterbox-TTS-Server or travisvn/chatterbox-tts-api) and "+ "set Base URL to its /v1 endpoint\n"+ "- Voices is a comma-separated list of voice names your server "+ "exposes; add a -Female or -Male suffix only to label the gender "+ "in this dropdown\n"+ "- Speech Volume is not applied for Chatterbox (the OpenAI "+ "/audio/speech API has no volume field); use Speech Rate instead"+ )+params.voice_volume = st.selectbox(tr("Speech Volume"),options=[0.6, 0.8, 1.0, 1.2, 1.5, 2.0, 3.0, 4.0, 5.0],diff --git a/webui/i18n/en.json b/webui/i18n/en.jsonindex e598b946..3732f87d 100644--- a/webui/i18n/en.json+++ b/webui/i18n/en.json@@ -126,6 +126,10 @@"MiMo TTS Settings": "Xiaomi MiMo TTS Settings","ElevenLabs API Key": "ElevenLabs API Key","ElevenLabs Model": "ElevenLabs Model",+ "Chatterbox Base URL": "Chatterbox Base URL",+ "Chatterbox API Key": "Chatterbox API Key",+ "Chatterbox Model": "Chatterbox Model",+ "Chatterbox Voices": "Chatterbox Voices","Uses Xiaomi MiMo V2.5 TTS preset voices": "Uses Xiaomi MiMo V2.5 TTS preset voices","Speed and volume are currently handled by the provider defaults": "Speed and volume are currently handled by the provider defaults","Hide Log": "Hide Log",diff --git a/webui/i18n/ru.json b/webui/i18n/ru.jsonindex f6ecb626..9a2ce862 100644--- a/webui/i18n/ru.json+++ b/webui/i18n/ru.json@@ -122,6 +122,10 @@"MiMo TTS Settings": "Настройки TTS Xiaomi MiMo","ElevenLabs API Key": "API-ключ ElevenLabs","ElevenLabs Model": "Модель ElevenLabs",+ "Chatterbox Base URL": "Базовый URL Chatterbox",+ "Chatterbox API Key": "API-ключ Chatterbox",+ "Chatterbox Model": "Модель Chatterbox",+ "Chatterbox Voices": "Голоса Chatterbox","Uses Xiaomi MiMo V2.5 TTS preset voices": "Используются предустановленные голоса Xiaomi MiMo V2.5","Speed and volume are currently handled by the provider defaults": "Скорость и громкость сейчас задаются настройками провайдера по умолчанию","Hide Log": "Скрыть журнал",