Files
AiVideo/engine/adapters/tts/edge_adapter.py
2026-03-25 19:35:37 +08:00

29 lines
767 B
Python

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())