Skip to content

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

Stabilize local TTS and video tests

CowCow7ef5aba2c15d3
diff --git a/app/services/voice.py b/app/services/voice.py
index 4920e079..9bb8ee58 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -4,6 +4,7 @@ import math
import os
import queue
import re
+import shutil
import threading
import time
from datetime import datetime
@@ -23,6 +24,20 @@ from app.utils import utils
_DEFAULT_EDGE_TTS_TIMEOUT_SECONDS = 30.0
+def _configure_pydub_ffmpeg(audio_segment_cls):
+ configured_ffmpeg = os.environ.get("IMAGEIO_FFMPEG_EXE") or shutil.which("ffmpeg")
+ if not configured_ffmpeg:
+ try:
+ import imageio_ffmpeg
+
+ configured_ffmpeg = imageio_ffmpeg.get_ffmpeg_exe()
+ except Exception as exc:
+ logger.warning(f"failed to resolve bundled ffmpeg binary: {str(exc)}")
+
+ if configured_ffmpeg:
+ audio_segment_cls.converter = configured_ffmpeg
+
+
def mktimestamp(time_unit: float) -> str:
"""
将 edge_tts 使用的 100 纳秒时间单位转换为字幕时间戳。
@@ -1760,6 +1775,7 @@ def gemini_tts(
import io
from pydub import AudioSegment
import google.generativeai as genai
+ _configure_pydub_ffmpeg(AudioSegment)
try:
# 配置Gemini API
diff --git a/test/services/test_video.py b/test/services/test_video.py
index 9daf77a6..f98a756d 100644
--- a/test/services/test_video.py
+++ b/test/services/test_video.py
@@ -111,7 +111,10 @@ class TestVideoService(unittest.TestCase):
# moviepy get video info
clip = VideoFileClip(materials[0].url)
- print(clip)
+ try:
+ print(clip)
+ finally:
+ clip.close()
# clean generated test video file
if os.path.exists(materials[0].url):
diff --git a/test/services/test_voice.py b/test/services/test_voice.py
index 7d15fc39..bb59429c 100644
--- a/test/services/test_voice.py
+++ b/test/services/test_voice.py
@@ -46,6 +46,12 @@ class TestVoiceService(unittest.TestCase):
self.loop.close()
def test_siliconflow(self):
+ # SiliconFlow 的 API Key 存在 [siliconflow].api_key 中,运行时代码也是从
+ # config.siliconflow 读取;这里必须使用同一配置源,避免正确配置凭据时
+ # 测试仍然被误跳过。
+ if not vs.config.siliconflow.get("api_key"):
+ self.skipTest("siliconflow_api_key is not configured")
+
voice_name = "siliconflow:FunAudioLLM/CosyVoice2-0.5B:alex-Male"
voice_name = vs.parse_voice_name(voice_name)
@@ -192,6 +198,9 @@ class TestVoiceService(unittest.TestCase):
self.assertLess(elapsed, 2)
def test_azure_tts_v2(self):
+ if not vs.config.azure.get("speech_key") or not vs.config.azure.get("speech_region"):
+ self.skipTest("Azure speech key or region is not configured")
+
voice_name = "zh-CN-XiaoxiaoMultilingualNeural-V2-Female"
voice_name = vs.parse_voice_name(voice_name)
print(voice_name)