Download code/pipeline_train/tts/src/vwtts/engine.py from thucdangvan020999/aurora-wake-model: direct link, hf CLI and curl.
- Browser
- Download file 3.43 kB
-
https://huggingface.co/thucdangvan020999/aurora-wake-model/resolve/main/code/pipeline_train/tts/src/vwtts/engine.py
- Command line
-
hf download hf://thucdangvan020999/aurora-wake-model/code/pipeline_train/tts/src/vwtts/engine.py
-
curl -L -o engine.py https://huggingface.co/thucdangvan020999/aurora-wake-model/resolve/main/code/pipeline_train/tts/src/vwtts/engine.py
3.43 kB
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from dataclasses import replace | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| from .adapters import create_adapter | |
| from .audio import augment_file, inspect_audio | |
| from .randomizer import resolve_seed, sample_config | |
| from .registry import ModelRegistry | |
| from .schema import GeneratedArtifact, GenerationRequest | |
| class GenerationEngine: | |
| def __init__(self, registry: ModelRegistry | None = None): | |
| self.registry = registry or ModelRegistry() | |
| def status(self) -> list[dict]: | |
| rows = [] | |
| for spec in self.registry.all(): | |
| available, reason = create_adapter(spec).available() | |
| rows.append({**spec.__dict__, "available": available, "status": reason}) | |
| return rows | |
| def generate(self, request: GenerationRequest) -> list[GeneratedArtifact]: | |
| request.validate() | |
| if request.model_id == "all-ready": | |
| ready_ids = [ | |
| row["id"] for row in self.status() | |
| if row["available"] and row["id"] != "diagnostic-tone" | |
| ] | |
| if not ready_ids: | |
| raise RuntimeError("no real model backends are ready") | |
| artifacts = [] | |
| for model_id in ready_ids: | |
| artifacts.extend(self.generate(replace(request, model_id=model_id))) | |
| return artifacts | |
| spec = self.registry.get(request.model_id) | |
| adapter = create_adapter(spec) | |
| ready, reason = adapter.available() | |
| if not ready: | |
| raise RuntimeError(f"model {spec.id} is not ready: {reason}") | |
| root_seed = resolve_seed(request.random_numpy) | |
| request.output_dir.mkdir(parents=True, exist_ok=True) | |
| artifacts = [] | |
| for index in range(request.variants): | |
| cfg = sample_config(root_seed, index) | |
| digest = hashlib.sha1( | |
| f"{spec.id}|{request.text_wakeupword}|{cfg.seed}".encode() | |
| ).hexdigest()[:12] | |
| stem = f"{spec.id}__{index:04d}__{digest}" | |
| audio_path = request.output_dir / f"{stem}.wav" | |
| metadata_path = request.output_dir / f"{stem}.json" | |
| adapter.synthesize( | |
| request.text_wakeupword, | |
| audio_path, | |
| cfg, | |
| request.audio_reference, | |
| request.reference_text, | |
| request.style_prompt, | |
| ) | |
| if request.augment: | |
| augment_file(audio_path, cfg) | |
| metadata = { | |
| "schema_version": 1, | |
| "created_at": datetime.now(timezone.utc).isoformat(), | |
| "text_wakeupword": request.text_wakeupword, | |
| "model": spec.__dict__, | |
| "root_seed": root_seed, | |
| "variant": index, | |
| "randomized_config": cfg.to_dict(), | |
| "audio_reference": str(request.audio_reference) if request.audio_reference else None, | |
| "reference_text": request.reference_text, | |
| "style_prompt": request.style_prompt, | |
| "augmentation_applied": request.augment, | |
| "audio": inspect_audio(audio_path), | |
| } | |
| metadata_path.write_text(json.dumps(metadata, ensure_ascii=False, indent=2), encoding="utf-8") | |
| artifacts.append(GeneratedArtifact(audio_path, metadata_path, spec.id, cfg.seed)) | |
| return artifacts | |