from __future__ import annotations import shutil import pytest from app.providers.base import FatalProviderError, VoiceGenRequest from app.providers.macos_say import ALIEN_AUDIO_FILTER, MacOSSayVoiceProvider from app.services import ffmpeg as ff pytestmark = pytest.mark.skipif( not shutil.which("say") or not ff.available(), reason="需要 macOS say 与 ffmpeg", ) def test_macos_say_generates_real_chinese_speech(tmp_path): output = tmp_path / "waiter.wav" result = MacOSSayVoiceProvider().synthesize( VoiceGenRequest( text="先生您好,今晚的头道菜是炭烤战斧牛排。", provider_voice_id="Tingting", language="zh-CN", output_path=output, ) ) assert output.exists() assert result.duration_ms >= 1000 assert result.metadata["real"] is True assert ff.probe(output).has_audio def test_macos_say_alien_effect_produces_audible_audio(tmp_path): output = tmp_path / "predator.wav" result = MacOSSayVoiceProvider().synthesize( VoiceGenRequest( text="Sssth. Ka-laa, tuuk. Hsss, raa-ka-ta.", provider_voice_id="Fred", language="en", params={"effect": "alien"}, output_path=output, ) ) assert output.exists() assert result.duration_ms >= 1000 assert result.metadata["effect"] == "alien" assert "acrusher" in ALIEN_AUDIO_FILTER def test_macos_say_rejects_empty_text(tmp_path): with pytest.raises(FatalProviderError, match="配音文本为空"): MacOSSayVoiceProvider().synthesize( VoiceGenRequest(text=" ", provider_voice_id="Tingting", output_path=tmp_path / "empty.wav") ) def test_voiceover_task_records_the_bound_macos_provider(api): pid = api.project() voice = api.post(f"/api/projects/{pid}/voices", json={ "name": "真实中文女声", "provider": "macos-say", "provider_voice_id": "Tingting", "language": "zh-CN", })["result"] shot = api.post(f"/api/projects/{pid}/shots", json={ "title": "报菜名", "description": "服务员端上菜", "duration": 5, "dialogue": "您的牛排,请慢用。", "voice_asset_id": voice["id"], })["result"] api.post(f"/api/projects/{pid}/voiceover", json={"shot_ids": [shot["id"]]}) task = next(t for t in api.get(f"/api/tasks?project_id={pid}&kind=voiceover")["tasks"] if t["shot_id"] == shot["id"]) assert task["provider"] == "macos-say", task assert task["model"] == "system-voice", task