Files
UmbraAudio/backup/author_voice_lab/scripts/install_ref.py
2026-10-18 19:01:04 -07:00

51 lines
1.7 KiB
Python

# Copyright 2026 Umbra Tools (umbratools.com)
# SPDX-License-Identifier: Apache-2.0
"""Install the matrix-derived Author reference into the project.
The matrix is the source of truth; this writes the WAV *decoded from that matrix*
so the project's reference and the matrix provably agree (LTAS 0.55 dB RMS,
median F0 within 0.8 Hz of the original capture).
"""
from __future__ import annotations
import hashlib
import json
import shutil
from datetime import datetime, timezone
from pathlib import Path
PROJECT = Path("/Volumes/1TB_APL_Storage/UmbraAudio")
DECODED = Path("/private/var/folders/y8/cbvhds297918lrxt2wd3btsr0000gn/T/opencode/probe_out/"
"author_ref_DECODED_FROM_MATRIX.wav")
VOICES = PROJECT / "DealHunterShip_4.0e_whole-to-audio/.umbra/voices"
MATRIX = PROJECT / "DealHunterShip_4.0e_whole-to-audio/.umbra/voice_prompts/author.pt"
def sha256(p: Path) -> str:
h = hashlib.sha256()
h.update(Path(p).read_bytes())
return h.hexdigest()
dest = VOICES / "author_ref.wav"
if dest.exists():
backup = VOICES / f"author_ref.PRE_MATRIX_DECODE.{datetime.now():%Y%m%d_%H%M%S}.wav"
shutil.copy2(dest, backup)
print(f"existing author_ref.wav -> {backup.name}")
shutil.copy2(DECODED, dest)
info = {
"installed": str(dest),
"decoded_from_matrix": str(MATRIX),
"matrix_sha256": sha256(MATRIX),
"ref_sha256": sha256(dest),
"provenance": "decoded from author.pt ref_code via Qwen3TTSTokenizer.decode()",
"note": ("Regenerate with the matrix only: "
"Qwen3TTSTokenizer.from_pretrained(models/Qwen3-TTS-12Hz-1.7B-Base/"
"speech_tokenizer).decode({'audio_codes': ref_code})"),
}
side = dest.with_suffix(".json")
side.write_text(json.dumps(info, indent=2) + "\n")
print(json.dumps(info, indent=2))