利用 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
feat: add MiniMax text-to-speech support
octo-patchfafa572ef52b
diff --git a/app/config/config.py b/app/config/config.pyindex 28af63af..4a22ebf3 100644--- a/app/config/config.py+++ b/app/config/config.py@@ -463,6 +463,7 @@ def save_config():config_to_save["app"] = dict(app)config_to_save["azure"] = dict(azure)config_to_save["siliconflow"] = dict(siliconflow)+ config_to_save["minimax_tts"] = dict(minimax_tts)config_to_save["elevenlabs"] = dict(elevenlabs)config_to_save["chatterbox"] = dict(chatterbox)config_to_save["ui"] = dict(ui)@@ -517,6 +518,7 @@ whisper = _cfg.get("whisper", {})proxy = _cfg.get("proxy", {})azure = _SynchronizedConfig(_cfg.get("azure", {}))siliconflow = _SynchronizedConfig(_cfg.get("siliconflow", {}))+minimax_tts = _SynchronizedConfig(_cfg.get("minimax_tts", {}))elevenlabs = _SynchronizedConfig(_cfg.get("elevenlabs", {}))chatterbox = _SynchronizedConfig(_cfg.get("chatterbox", {}))ui = _SynchronizedConfig(diff --git a/app/services/voice.py b/app/services/voice.pyindex 3ef5fb85..e7b1841d 100644--- a/app/services/voice.py+++ b/app/services/voice.py@@ -29,6 +29,14 @@ from app.utils import utils_DEFAULT_EDGE_TTS_TIMEOUT_SECONDS = 30.0_MIMO_DEFAULT_BASE_URL = "https://api.xiaomimimo.com/v1"_MIMO_DEFAULT_TTS_MODEL = "mimo-v2.5-tts"+MINIMAX_TTS_GLOBAL_URL = "https://api.minimax.io/v1/t2a_v2"+MINIMAX_TTS_CN_URL = "https://api.minimaxi.com/v1/t2a_v2"+MINIMAX_TTS_DEFAULT_MODEL = "speech-2.8-hd"+MINIMAX_TTS_DEFAULT_VOICE = "English_expressive_narrator"+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",+)NO_VOICE_NAME = "no-voice"# `none` 是 PR #981 里曾使用过的无配音标识。这里短期兼容这个值,避免# 已经手动调用过该分支的 API 用户升级后立即失效;WebUI 和新代码统一使用@@ -139,6 +147,12 @@ def get_mimo_voices() -> list[str]:return [f"mimo:{voice}-{gender}" for voice, gender in voices_with_gender]+def get_minimax_voices() -> list[str]:+ """Return the configured MiniMax voice for the TTS selector."""+ voice_id = str(config.minimax_tts.get("voice_id", MINIMAX_TTS_DEFAULT_VOICE) or MINIMAX_TTS_DEFAULT_VOICE).strip()+ return [f"minimax:{voice_id}"]++def get_elevenlabs_voices(api_key: str) -> list[str]:if not api_key:return []@@ -248,6 +262,10 @@ def is_mimo_voice(voice_name: str):return voice_name.startswith("mimo:")+def is_minimax_voice(voice_name: str | None) -> bool:+ return (voice_name or "").startswith("minimax:")++def is_elevenlabs_voice(voice_name: str) -> bool:return (voice_name or "").startswith("elevenlabs:")@@ -433,6 +451,12 @@ def tts(else:logger.error(f"Invalid mimo voice name format: {voice_name}")return None+ elif is_minimax_voice(voice_name):+ voice_id = voice_name.split(":", 1)[1].strip()+ if voice_id:+ return minimax_tts(text, voice_id, voice_rate, voice_file, voice_volume)+ logger.error(f"Invalid MiniMax voice name format: {voice_name}")+ return Noneelif is_elevenlabs_voice(voice_name):# 格式: elevenlabs:{voice_id}:{name}parts = voice_name.split(":")@@ -1287,6 +1311,85 @@ def mimo_tts(return None+def _resolve_minimax_tts_url(configured_url: str) -> str:+ configured_url = (configured_url or "").strip().rstrip("/")+ if not configured_url:+ return MINIMAX_TTS_GLOBAL_URL+ if configured_url in {MINIMAX_TTS_GLOBAL_URL, MINIMAX_TTS_CN_URL}:+ return configured_url+ if configured_url.endswith("/v1"):+ return f"{configured_url}/t2a_v2"+ return configured_url+++def minimax_tts(text: str, voice_id: str, voice_rate: float, voice_file: str, voice_volume: float = 1.0) -> Union[SubMaker, None]:+ """Generate speech with the synchronous MiniMax T2A HTTP API."""+ text, voice_id = (text or "").strip(), (voice_id or "").strip()+ if not text or not voice_id:+ logger.error("MiniMax TTS requires text and a voice ID")+ return None+ settings = config.minimax_tts+ api_key = str(settings.get("api_key", "") or config.app.get("minimax_api_key", "") or "").strip()+ if not api_key:+ logger.error("MiniMax TTS API key is not set")+ return None+ url = _resolve_minimax_tts_url(str(settings.get("base_url", "") or ""))+ model = str(settings.get("model_id", MINIMAX_TTS_DEFAULT_MODEL) or MINIMAX_TTS_DEFAULT_MODEL).strip()+ if model not in MINIMAX_TTS_MODELS:+ logger.error(f"Unsupported MiniMax TTS model: {model}")+ return None+ try:+ speed = max(0.5, min(2.0, float(voice_rate or 1.0)))+ volume = max(0.0, min(10.0, float(voice_volume or 1.0)))+ pitch = max(-12, min(12, int(settings.get("pitch", 0) or 0)))+ sample_rate = int(settings.get("sample_rate", 32000) or 32000)+ bitrate = int(settings.get("bitrate", 128000) or 128000)+ channel = int(settings.get("channel", 1) or 1)+ except (TypeError, ValueError) as exc:+ logger.error(f"Invalid MiniMax TTS audio setting: {str(exc)}")+ return None+ audio_format = str(settings.get("audio_format", "mp3") or "mp3").strip()+ if audio_format not in {"mp3", "wav", "flac", "pcm"}:+ logger.error(f"Unsupported MiniMax TTS audio format: {audio_format}")+ return None+ payload = {+ "model": model, "text": text, "stream": False, "language_boost": "auto", "output_format": "hex",+ "voice_setting": {"voice_id": voice_id, "speed": speed, "vol": volume, "pitch": pitch},+ "audio_setting": {"sample_rate": sample_rate, "bitrate": bitrate, "format": audio_format, "channel": channel},+ }+ headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}+ for attempt in range(3):+ try:+ logger.info(f"start MiniMax TTS, model: {model}, voice: {voice_id}, try: {attempt + 1}")+ response = requests.post(url, json=payload, headers=headers, timeout=120)+ if response.status_code != 200:+ logger.error(f"MiniMax TTS failed with status {response.status_code}: {response.text[:200]}")+ continue+ body = response.json()+ data = body.get("data") or {}+ base_resp = body.get("base_resp") or {}+ if base_resp.get("status_code") != 0 or data.get("status") != 2:+ logger.error(f"MiniMax TTS returned an unsuccessful response: status_code={base_resp.get('status_code')}, audio_status={data.get('status')}")+ continue+ audio_hex = data.get("audio")+ if not isinstance(audio_hex, str) or not audio_hex:+ logger.error("MiniMax TTS returned empty audio data")+ continue+ ensure_file_path_exists(voice_file)+ with open(voice_file, "wb") as output:+ output.write(bytes.fromhex(audio_hex))+ audio_clip = AudioFileClip(voice_file)+ audio_duration = audio_clip.duration+ audio_clip.close()+ logger.success(f"MiniMax TTS succeeded: {voice_file}")+ return populate_legacy_submaker_with_full_text(+ ensure_legacy_submaker_fields(SubMaker()), text, audio_duration+ )+ except (OSError, ValueError, requests.RequestException) as exc:+ logger.error(f"MiniMax TTS failed: {str(exc)}")+ return None++def elevenlabs_tts(text: str,voice_id: str,diff --git a/config.example.toml b/config.example.tomlindex 2be87616..afac1962 100644--- a/config.example.toml+++ b/config.example.toml@@ -314,6 +314,21 @@ speech_region = ""# SiliconFlow TTS API key: https://siliconflow.cn/api_key = ""+[minimax_tts]+# API key: https://platform.minimax.io/user-center/basic-information/interface-key+# Global endpoint: https://api.minimax.io/v1/t2a_v2+# China endpoint: https://api.minimaxi.com/v1/t2a_v2+# The MiniMax text-generation API key is used as a fallback when this is empty.+api_key = ""+base_url = "https://api.minimax.io/v1/t2a_v2"+model_id = "speech-2.8-hd"+voice_id = "English_expressive_narrator"+sample_rate = 32000+bitrate = 128000+audio_format = "mp3"+channel = 1+pitch = 0+[elevenlabs]# API key: https://elevenlabs.io/app/settings/api-keys# Favorite voices in the ElevenLabs voice library are shown in the WebUI.diff --git a/test/services/test_voice.py b/test/services/test_voice.pyindex 5e4c8a09..37c0a604 100644--- a/test/services/test_voice.py+++ b/test/services/test_voice.py@@ -587,6 +587,58 @@ class TestVoiceService(unittest.TestCase):self.assertEqual(getattr(sub_maker, "subs", []), ["小米语音合成测试", "第二句话"])self.assertEqual(len(getattr(sub_maker, "offset", [])), 2)+ def test_minimax_tts_uses_regional_endpoint_and_hex_audio(self):+ class _Response:+ status_code, text = 200, ""++ @staticmethod+ def json():+ return {"data": {"audio": b"audio".hex(), "status": 2}, "base_resp": {"status_code": 0}}++ class _Clip:+ duration = 2.5++ def close(self):+ pass++ captured = {}++ def _post(url, json=None, headers=None, timeout=None):+ captured.update(url=url, json=json, headers=headers, timeout=timeout)+ return _Response()++ settings = {+ "api_key": "test-key", "base_url": vs.MINIMAX_TTS_CN_URL,+ "model_id": "speech-2.8-turbo", "voice_id": "male-qn-qingse",+ "sample_rate": 32000, "bitrate": 128000, "audio_format": "mp3", "channel": 1,+ }+ with tempfile.TemporaryDirectory() as tmp_dir, patch.object(+ vs.config, "minimax_tts", settings+ ), patch.object(vs.requests, "post", side_effect=_post), patch.object(+ vs, "AudioFileClip", return_value=_Clip()+ ):+ voice_file = str(Path(tmp_dir) / "minimax.mp3")+ result = vs.minimax_tts("Speech test.", "male-qn-qingse", 1.2, voice_file, 1.5)+ self.assertEqual(Path(voice_file).read_bytes(), b"audio")++ self.assertIsNotNone(result)+ self.assertEqual(captured["url"], "https://api.minimaxi.com/v1/t2a_v2")+ self.assertEqual(captured["headers"]["Authorization"], "Bearer test-key")+ self.assertEqual(captured["json"]["model"], "speech-2.8-turbo")+ self.assertEqual(captured["json"]["text"], "Speech test.")+ self.assertEqual(captured["json"]["voice_setting"]["voice_id"], "male-qn-qingse")+ self.assertEqual(captured["json"]["audio_setting"]["format"], "mp3")++ def test_minimax_voice_helpers_and_dispatch(self):+ with patch.object(vs.config, "minimax_tts", {"voice_id": "narrator"}):+ self.assertEqual(vs.get_minimax_voices(), ["minimax:narrator"])+ self.assertTrue(vs.is_minimax_voice("minimax:narrator"))+ sentinel = object()+ with patch.object(vs, "minimax_tts", return_value=sentinel) as implementation:+ result = vs.tts("test", "minimax:narrator", 1.0, "voice.mp3", 1.0)+ self.assertIs(result, sentinel)+ implementation.assert_called_once_with("test", "narrator", 1.0, "voice.mp3", 1.0)+def test_chatterbox_voice_helpers(self):"""is_chatterbox_voice / get_chatterbox_voices basics and normalisation."""self.assertTrue(vs.is_chatterbox_voice("chatterbox:default-Female"))diff --git a/webui/Main.py b/webui/Main.pyindex f386944e..3f20e75a 100644--- a/webui/Main.py+++ b/webui/Main.py@@ -126,6 +126,7 @@ _RUNTIME_CONFIG_SECTIONS = {"azure": config.azure,"chatterbox": config.chatterbox,"elevenlabs": config.elevenlabs,+ "minimax_tts": config.minimax_tts,"siliconflow": config.siliconflow,"ui": config.ui,}@@ -951,6 +952,8 @@ def _infer_tts_server_from_voice(voice_name):return "gemini-tts"if voice.is_mimo_voice(voice_name):return "mimo-tts"+ if voice.is_minimax_voice(voice_name):+ return "minimax-tts"if voice.is_elevenlabs_voice(voice_name):return "elevenlabs"if voice.is_chatterbox_voice(voice_name):@@ -2663,6 +2666,16 @@ def _get_voice_preview_provider_signature(tts_server: str) -> dict:}if tts_server == "mimo-tts":return {"credential": _credential_signature(config.app.get("mimo_api_key", ""))}+ if tts_server == "minimax-tts":+ return {+ "base_url": config.minimax_tts.get("base_url", ""),+ "model_id": config.minimax_tts.get("model_id", ""),+ "voice_id": config.minimax_tts.get("voice_id", ""),+ "credential": _credential_signature(+ config.minimax_tts.get("api_key", "")+ or config.app.get("minimax_api_key", "")+ ),+ }if tts_server == "elevenlabs":return {"model_id": config.elevenlabs.get("model_id", ""),@@ -3247,6 +3260,7 @@ def _render_audio_settings(panel, params):("siliconflow", "SiliconFlow TTS"),("gemini-tts", "Google Gemini TTS"),("mimo-tts", "Xiaomi MiMo TTS"),+ ("minimax-tts", "MiniMax TTS"),("elevenlabs", "ElevenLabs TTS"),("chatterbox", "Chatterbox TTS"),]@@ -3295,6 +3309,8 @@ def _render_audio_settings(panel, params):elif selected_tts_server == "mimo-tts":# 获取 Xiaomi MiMo TTS 的预置音色列表filtered_voices = voice.get_mimo_voices()+ elif selected_tts_server == "minimax-tts":+ filtered_voices = voice.get_minimax_voices()elif selected_tts_server == "elevenlabs":# 音色列表位于 Key 输入框之前渲染,必须先统一恢复重连状态并读取# 配置/环境变量,否则页面会用空 Key 加载并缓存空音色列表。@@ -3333,6 +3349,8 @@ def _render_audio_settings(panel, params):if voice.is_chatterbox_voice(v):name = v.split(":", 1)[1] if ":" in v else vreturn name.replace("-Female", "").replace("-Male", "")+ if voice.is_minimax_voice(v):+ return v.split(":", 1)[1]return (v.replace("Female", tr("Female")).replace("Male", tr("Male"))@@ -3454,6 +3472,59 @@ def _render_audio_settings(panel, params):_set_runtime_config("app", "mimo_api_key", mimo_api_key)+ if tts_mode_enabled and (+ selected_tts_server == "minimax-tts"+ or (voice_name and voice.is_minimax_voice(voice_name))+ ):+ minimax_tts_api_key = st.text_input(+ tr("MiniMax TTS API Key"),+ value=config.minimax_tts.get("api_key", ""),+ type="password",+ key="minimax_tts_api_key_input",+ )+ _set_runtime_config("minimax_tts", "api_key", minimax_tts_api_key)++ minimax_tts_endpoints = [+ voice.MINIMAX_TTS_GLOBAL_URL,+ voice.MINIMAX_TTS_CN_URL,+ ]+ configured_endpoint = config.minimax_tts.get(+ "base_url", voice.MINIMAX_TTS_GLOBAL_URL+ )+ if configured_endpoint not in minimax_tts_endpoints:+ configured_endpoint = voice.MINIMAX_TTS_GLOBAL_URL+ minimax_tts_base_url = stable_selectbox(+ tr("MiniMax TTS Endpoint"),+ options=minimax_tts_endpoints,+ default_value=configured_endpoint,+ key="minimax_tts_endpoint_select",+ )+ _set_runtime_config("minimax_tts", "base_url", minimax_tts_base_url)++ configured_model = config.minimax_tts.get(+ "model_id", voice.MINIMAX_TTS_DEFAULT_MODEL+ )+ if configured_model not in voice.MINIMAX_TTS_MODELS:+ configured_model = voice.MINIMAX_TTS_DEFAULT_MODEL+ minimax_tts_model = stable_selectbox(+ tr("MiniMax TTS Model"),+ options=list(voice.MINIMAX_TTS_MODELS),+ default_value=configured_model,+ key="minimax_tts_model_select",+ )+ _set_runtime_config("minimax_tts", "model_id", minimax_tts_model)++ minimax_tts_voice_id = st.text_input(+ tr("MiniMax TTS Voice ID"),+ value=config.minimax_tts.get(+ "voice_id", voice.MINIMAX_TTS_DEFAULT_VOICE+ ),+ key="minimax_tts_voice_id_input",+ )+ _set_runtime_config(+ "minimax_tts", "voice_id", minimax_tts_voice_id.strip()+ )+# ElevenLabs API key sectionif tts_mode_enabled and (selected_tts_server == "elevenlabs"