fix: 优化架构
This commit is contained in:
1
engine/adapters/tts/__init__.py
Normal file
1
engine/adapters/tts/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
9
engine/adapters/tts/base.py
Normal file
9
engine/adapters/tts/base.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class BaseTTS:
|
||||
def generate(self, text: str, output_path: str | Path) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
28
engine/adapters/tts/edge_adapter.py
Normal file
28
engine/adapters/tts/edge_adapter.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from engine.audio_gen import synthesize_one
|
||||
from engine.config import AppConfig
|
||||
|
||||
from .base import BaseTTS
|
||||
|
||||
|
||||
class EdgeTTS(BaseTTS):
|
||||
def __init__(self, cfg: AppConfig):
|
||||
self.cfg = cfg
|
||||
|
||||
def generate(self, text: str, output_path: str | Path) -> str:
|
||||
text = text or " "
|
||||
output_path = Path(output_path)
|
||||
voice = str(self.cfg.get("tts.voice", "zh-CN-XiaoxiaoNeural"))
|
||||
rate = str(self.cfg.get("tts.rate", "+0%"))
|
||||
volume = str(self.cfg.get("tts.volume", "+0%"))
|
||||
|
||||
async def _run():
|
||||
asset = await synthesize_one(text, output_path, voice, rate, volume)
|
||||
return str(asset.path)
|
||||
|
||||
return asyncio.run(_run())
|
||||
|
||||
15
engine/adapters/tts/mock_adapter.py
Normal file
15
engine/adapters/tts/mock_adapter.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from .base import BaseTTS
|
||||
|
||||
|
||||
class MockTTS(BaseTTS):
|
||||
def generate(self, text: str, output_path: str | Path) -> str:
|
||||
# No-op for offline tests: return empty path so video adapter skips audio.
|
||||
output_path = Path(output_path)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
output_path.write_bytes(b"")
|
||||
return str(output_path)
|
||||
|
||||
Reference in New Issue
Block a user