Files
MoneyPrinterTurbo/test/services/test_api_video_default_voice.py
TanishqandHarry c2868a6774 fix(api): give /videos requests without voice_name the default voice of /audio and /subtitle
POST /api/v1/videos defaulted voice_name to "", where /audio and
/subtitle default to zh-CN-XiaoxiaoNeural-Female. Edge TTS accepts no
empty voice ("Invalid voice ''."), so a request without voice_name ran
the script and terms LLM calls and then failed at the audio stage,
after three TTS attempts. The API docs at /docs and /redoc showed the
empty default.

TaskVideoRequest now defaults voice_name to the voice of /audio and
/subtitle, which is also the CLI's built-in default. VideoParams keeps
its empty default, so the CLI and the WebUI are unchanged, and a
request that sends a voice_name still gets that voice.
2026-11-13 14:44:00 +08:00

64 lines
2.0 KiB
Python

"""A /videos request without voice_name narrates with the voice that /audio and /subtitle use."""
from unittest.mock import patch
import pytest
from fastapi.testclient import TestClient
from app import asgi
from app.config import config
from app.controllers.v1 import video as video_controller
from app.models.schema import TaskVideoRequest
from app.services import voice
DEFAULT_VOICE_NAME = "zh-CN-XiaoxiaoNeural-Female"
@pytest.fixture
def client(monkeypatch):
monkeypatch.setitem(config.app, "api_key", "")
return TestClient(asgi.app)
def queued_voice(client, endpoint, body):
"""Return the voice_name of the task that a request queues."""
with (
patch.object(video_controller.sm.state, "update_task"),
patch.object(video_controller.task_manager, "add_task") as add_task,
):
response = client.post(endpoint, json=body)
assert response.status_code == 200
return add_task.call_args.kwargs["params"].voice_name
def test_video_request_without_voice_uses_the_audio_and_subtitle_voice(client):
assert (
queued_voice(client, "/api/v1/audio", {"video_script": "Coffee"})
== DEFAULT_VOICE_NAME
)
assert (
queued_voice(client, "/api/v1/subtitle", {"video_script": "Coffee"})
== DEFAULT_VOICE_NAME
)
assert (
queued_voice(client, "/api/v1/videos", {"video_subject": "Coffee"})
== DEFAULT_VOICE_NAME
)
def test_api_docs_show_the_default_voice_for_video_requests(client):
# The API docs at /docs and /redoc show this default.
schemas = client.get("/openapi.json").json()["components"]["schemas"]
assert (
schemas["TaskVideoRequest"]["properties"]["voice_name"]["default"]
== DEFAULT_VOICE_NAME
)
def test_default_video_voice_is_an_edge_voice():
# Edge TTS rejects an empty voice with "Invalid voice ''." before it connects.
voice_name = voice.parse_voice_name(
TaskVideoRequest(video_subject="Coffee").voice_name
)
assert voice.create_edge_tts_communicate("Coffee", voice_name, "+0%")