Files
Shaman 82c306ff69 init
2026-10-01 07:38:01 +03:00

32 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Совместимый шим над silero_tts (для OpenCode-проекта silero_open_ai).
# Пакет silero-tts>=6.0 из pyproject.toml — приватный билд OpenCode'а, на PyPI таково нет.
# Даёт интерфейс, который ожидает app/synthesis.py: SileroTTS(...).tts_model.apply_tts(...)
# Модель грузится из models/<model_id>.pt (torch.package) — сеть не нужна.
import os
import torch
_MODELS_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "models")
class SileroTTS:
def __init__(self, model_id: str, language: str = "ru", speaker: str = "baya",
sample_rate: int = 24000, device: str = "cpu", num_threads: int = 4,
**kwargs):
self.language = language
self.speaker = speaker
self.sample_rate = int(sample_rate)
self.put_accent = kwargs.pop("put_accent", True)
self.put_yo = kwargs.pop("put_yo", True)
torch.set_num_threads(int(num_threads))
path = os.path.join(_MODELS_DIR, f"{model_id}.pt")
if not os.path.isfile(path):
raise FileNotFoundError(f"model not found: {path}")
self.tts_model = torch.package.PackageImporter(path).load_pickle("tts_models", "model")
try:
self.tts_model.to(torch.device(device))
except (AttributeError, NotImplementedError):
pass # модель без .to() — остаётся на CPU