Skip to content

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

feat(tts): add Fish Audio TTS provider and free developer model support

Hariom paswan9857c1fcb528
diff --git a/README.md b/README.md
index 9ef61cd6..6099b70b 100644
--- a/README.md
+++ b/README.md
@@ -137,7 +137,7 @@
- [x] 支持 **批量视频生成**,可以一次生成多个视频,然后选择一个最满意的
- [x] 支持 **视频片段时长** 设置,方便调节素材切换频率
- [x] 支持 **多语言视频脚本** 生成
-- [x] 支持 **Edge TTS**、**Azure Speech**、**SiliconFlow**、**Google Gemini**、**小米 MiMo**、**ElevenLabs** 和 **Chatterbox** 语音合成,可实时试听
+- [x] 支持 **Edge TTS**、**Azure Speech**、**SiliconFlow**、**Google Gemini**、**小米 MiMo**、**ElevenLabs**、**Chatterbox** 和 **Fish Audio** 语音合成,可实时试听
- [x] 支持 **字幕生成**,可调整字体、位置、颜色、大小、描边和背景样式
- [x] 支持 **背景音乐**,可随机选择或使用指定音乐,并调整音量
- [x] 支持使用自己的 **本地素材**,也可从 **Pexels**、**Pixabay** 和 **Coverr** 获取可免费使用的高清素材
@@ -366,7 +366,7 @@ uv run python cli.py --help
## 语音合成 🗣
-默认使用免费的 **Edge TTS**,在 WebUI 中显示为 **Azure TTS V1**。项目同时支持 **Azure TTS V2**、**SiliconFlow TTS**、**Google Gemini TTS**、**小米 MiMo TTS**、**ElevenLabs TTS**、自托管 **Chatterbox TTS**,以及无配音模式。
+默认使用免费的 **Edge TTS**,在 WebUI 中显示为 **Azure TTS V1**。项目同时支持 **Azure TTS V2**、**SiliconFlow TTS**、**Google Gemini TTS**、**小米 MiMo TTS**、**ElevenLabs TTS**、自托管 **Chatterbox 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 ba5cefbf..1f5f19ea 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["fish_audio"] = dict(fish_audio)
config_to_save["ui"] = dict(ui)
serialized_config = toml.dumps(config_to_save)
@@ -552,6 +553,7 @@ siliconflow = _SynchronizedConfig(_cfg.get("siliconflow", {}))
minimax_tts = _SynchronizedConfig(_cfg.get("minimax_tts", {}))
elevenlabs = _SynchronizedConfig(_cfg.get("elevenlabs", {}))
chatterbox = _SynchronizedConfig(_cfg.get("chatterbox", {}))
+fish_audio = _SynchronizedConfig(_cfg.get("fish_audio", {}))
ui = _SynchronizedConfig(
_cfg.get(
"ui",
diff --git a/app/services/voice.py b/app/services/voice.py
index 85f66243..d4d46f2a 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -221,6 +221,15 @@ def get_chatterbox_voices() -> list[str]:
return result
+def get_fish_audio_voices() -> list[str]:
+ """获取 Fish Audio 预置声音与模型列表。"""
+ return [
+ "fish_audio:s2.1-pro-free:Free-Developer",
+ "fish_audio:s2.1-pro:Pro-Voice",
+ "fish_audio:s2-pro:Pro-Voice",
+ ]
+
+
_AZURE_VOICES_DATA_FILE = os.path.join(
os.path.dirname(__file__), "data", "azure_voices.json"
)
@@ -313,6 +322,15 @@ def is_chatterbox_voice(voice_name: str) -> bool:
return (voice_name or "").startswith("chatterbox:")
+def is_fish_audio_voice(voice_name: str) -> bool:
+ return (voice_name or "").startswith("fish_audio:")
+
+
+def get_fish_audio_api_key() -> str:
+ configured_key = str(config.fish_audio.get("api_key", "") if hasattr(config, "fish_audio") and isinstance(config.fish_audio, dict) else "").strip()
+ return configured_key or os.getenv("FISH_API_KEY", "").strip()
+
+
def is_no_voice(voice_name: str | None) -> bool:
"""
判断用户是否明确选择了“无配音”模式。
@@ -503,6 +521,10 @@ def tts(
else:
logger.error(f"Invalid chatterbox voice name format: {voice_name}")
return None
+ elif is_fish_audio_voice(voice_name):
+ parts = voice_name.split(":")
+ model_name = parts[1] if len(parts) >= 2 else "s2.1-pro-free"
+ return fish_audio_tts(text, model_name, voice_file, voice_rate, voice_volume)
return azure_tts_v1(text, voice_name, voice_rate, voice_file)
@@ -1742,6 +1764,75 @@ def chatterbox_tts(
return None
+def fish_audio_tts(
+ text: str,
+ model_name: str,
+ voice_file: str,
+ voice_rate: float = 1.0,
+ voice_volume: float = 1.0,
+) -> Union[SubMaker, None]:
+ """Generate speech using Fish Audio TTS API."""
+ text = (text or "").strip()
+ if not text:
+ logger.error("Fish Audio TTS text is empty")
+ return None
+
+ api_key = get_fish_audio_api_key()
+ if not api_key:
+ logger.error(
+ "Fish Audio API key is not set. Please set it in config.toml [fish_audio] or FISH_API_KEY environment variable."
+ )
+ return None
+
+ url = "https://api.fish.audio/v1/tts"
+ headers = {
+ "Authorization": f"Bearer {api_key}",
+ "Content-Type": "application/json",
+ "model": model_name or "s2.1-pro-free",
+ }
+ payload = {
+ "text": text,
+ "format": "mp3",
+ }
+
+ for i in range(3):
+ try:
+ logger.info(f"start fish audio tts, model: {model_name}, try: {i + 1}")
+ ensure_file_path_exists(voice_file)
+
+ response = requests.post(url, json=payload, headers=headers, timeout=60)
+ if response.status_code != 200:
+ if response.status_code == 402:
+ logger.error(
+ "Fish Audio TTS failed: Insufficient API credit (402). "
+ "Please use model 's2.1-pro-free' or visit https://fish.audio/app/developers to add funds."
+ )
+ return None
+ logger.error(
+ f"fish audio tts failed with status {response.status_code}: {response.text[:200]}"
+ )
+ continue
+
+ with open(voice_file, "wb") as f:
+ f.write(response.content)
+
+ audio_clip = AudioFileClip(voice_file)
+ audio_duration = audio_clip.duration
+ audio_clip.close()
+
+ sub_maker = ensure_legacy_submaker_fields(SubMaker())
+ logger.success(f"fish audio 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"fish audio tts failed: {str(e)}")
+
+ return None
+
+
def _format_text(text: str) -> str:
"""
清理字幕对齐前的脚本文本。
diff --git a/config.example.toml b/config.example.toml
index 2b29c3ec..3a5d170f 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -396,6 +396,14 @@ model_id = "chatterbox"
# Voice names exposed by the configured Chatterbox server.
voices = ["default-Female"]
+[fish_audio]
+# Fish Audio TTS service: https://fish.audio
+# API key: https://fish.audio/app/developers
+# You can also set the FISH_API_KEY environment variable.
+api_key = ""
+# Available models: "s2.1-pro-free" (free developer tier), "s2.1-pro", "s2-pro"
+model = "s2.1-pro-free"
+
# =============================================================================
# WebUI Preferences / WebUI 偏好
# =============================================================================
diff --git a/webui.sh b/webui.sh
index 27027c45..866df9cf 100644
--- a/webui.sh
+++ b/webui.sh
@@ -17,14 +17,14 @@ MPT_WEBUI_HOST="${MPT_WEBUI_HOST:-127.0.0.1}"
MPT_WEBUI_PORT="${MPT_WEBUI_PORT:-8501}"
if [ -x "$CURRENT_DIR/.venv/bin/python" ]; then
- PORT_CHECK_CMD="$CURRENT_DIR/.venv/bin/python"
+ PORT_CHECK_EXEC="$CURRENT_DIR/.venv/bin/python"
set -- "$CURRENT_DIR/.venv/bin/python" -m streamlit
elif command -v uv >/dev/null 2>&1; then
- PORT_CHECK_CMD="uv run python"
+ PORT_CHECK_EXEC="uv"
set -- uv run streamlit
elif command -v streamlit >/dev/null 2>&1; then
echo "***** Warning: using streamlit from PATH. If dependencies fail, run 'uv sync --frozen' first. *****"
- PORT_CHECK_CMD="python3"
+ PORT_CHECK_EXEC="python3"
set -- streamlit
else
echo "***** Neither project Python, uv, nor streamlit was found. Please install dependencies first. *****"
@@ -32,7 +32,8 @@ else
fi
find_available_port() {
- WEBUI_HOST="$MPT_WEBUI_HOST" WEBUI_PORT="$MPT_WEBUI_PORT" "$@" - <<'PY' 2>/dev/null
+ if [ "$1" = "uv" ]; then
+ WEBUI_HOST="$MPT_WEBUI_HOST" WEBUI_PORT="$MPT_WEBUI_PORT" uv run python - <<'PY' 2>/dev/null
import os
import socket
import sys
@@ -52,11 +53,32 @@ for port in candidates:
sys.exit(1)
PY
+ else
+ WEBUI_HOST="$MPT_WEBUI_HOST" WEBUI_PORT="$MPT_WEBUI_PORT" "$1" - <<'PY' 2>/dev/null
+import os
+import socket
+import sys
+
+host = os.environ.get("WEBUI_HOST", "127.0.0.1")
+preferred = int(os.environ.get("WEBUI_PORT", "8501"))
+candidates = [preferred] + [port for port in range(8502, 8600) if port != preferred]
+
+for port in candidates:
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+ try:
+ sock.bind((host, port))
+ except OSError:
+ continue
+ print(port)
+ sys.exit(0)
+
+sys.exit(1)
+PY
+ fi
}
# 用 Python 做端口探测,避免依赖 lsof/nc 在不同 macOS/Linux 发行版上的差异。
-# shellcheck disable=SC2086
-SELECTED_WEBUI_PORT=$(find_available_port $PORT_CHECK_CMD)
+SELECTED_WEBUI_PORT=$(find_available_port "$PORT_CHECK_EXEC")
if [ -z "$SELECTED_WEBUI_PORT" ]; then
echo "***** No available WebUI port found in 8501-8599 for $MPT_WEBUI_HOST. *****"
diff --git a/webui/Main.py b/webui/Main.py
index 2d65acc2..a83630ea 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -138,6 +138,7 @@ _RUNTIME_CONFIG_SECTIONS = {
"elevenlabs": config.elevenlabs,
"minimax_tts": config.minimax_tts,
"siliconflow": config.siliconflow,
+ "fish_audio": config.fish_audio,
"ui": config.ui,
}
# 设置预设与密钥备份使用各自的文件标识。导入时先校验 schema 和版本,
@@ -4773,6 +4774,7 @@ def _render_audio_settings(panel, params):
("minimax-tts", "MiniMax TTS"),
("elevenlabs", "ElevenLabs TTS"),
("chatterbox", "Chatterbox TTS"),
+ ("fish_audio", "Fish Audio TTS (Free Developer)"),
]
tts_server_values = [server_value for server_value, _ in tts_servers]
@@ -4842,6 +4844,8 @@ 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 == "fish_audio":
+ filtered_voices = voice.get_fish_audio_voices()
else:
# 获取Azure的声音列表
all_voices = voice.get_all_azure_voices(filter_locals=None)
@@ -4868,6 +4872,8 @@ def _render_audio_settings(panel, params):
return name.replace("-Female", "").replace("-Male", "")
if voice.is_minimax_voice(v):
return minimax_voice_labels.get(v, v.split(":", 1)[1])
+ if voice.is_fish_audio_voice(v):
+ return v
return (
v.replace("Female", tr("Female"))
.replace("Male", tr("Male"))
@@ -5051,6 +5057,31 @@ def _render_audio_settings(panel, params):
)
_set_runtime_config("elevenlabs", "model_id", elevenlabs_model)
+ # Fish Audio API settings section (API key is read securely server-side from config.toml, never rendered in the UI)
+ if tts_mode_enabled and (
+ selected_tts_server == "fish_audio"
+ or (voice_name and voice.is_fish_audio_voice(voice_name))
+ ):
+ _fish_audio_models = [
+ "s2.1-pro-free",
+ "s2.1-pro",
+ "s2-pro",
+ ]
+ saved_fish_model = (
+ config.fish_audio.get("model", "s2.1-pro-free")
+ if hasattr(config, "fish_audio") and isinstance(config.fish_audio, dict)
+ else "s2.1-pro-free"
+ )
+ if saved_fish_model not in _fish_audio_models:
+ saved_fish_model = "s2.1-pro-free"
+ fish_model = stable_selectbox(
+ "Fish Audio Model",
+ options=_fish_audio_models,
+ default_value=saved_fish_model,
+ key="fish_audio_model_select",
+ )
+ _set_runtime_config("fish_audio", "model", fish_model)
+
# Chatterbox API settings section (self-hosted, OpenAI-compatible)
if tts_mode_enabled and (
selected_tts_server == "chatterbox"