Files
Athena-Deck/docs/experiments/audio8-cpu-2026-10-27/register_voices.py
T

47 lines
2.3 KiB
Python

"""Encode only three existing Anna excerpts into own Audio8 test voice profiles."""
import os
os.environ.update(CUDA_VISIBLE_DEVICES='', HF_HUB_OFFLINE='1',
HF_HUB_DISABLE_TELEMETRY='1', OPENBLAS_NUM_THREADS='1', OMP_NUM_THREADS='4')
from pathlib import Path
import hashlib
import json
import resource
import sys
import time
import onnxruntime as ort
ROOT = Path('/data/athena-audio8-cpu-20261027')
REFS = Path('/data/athena-articulino-references-20261027/references')
sys.path.insert(0, str(ROOT/'source/onnx_runtime_0_1b_int8'))
from arktts_runtime.registration import VoiceRegistration
manifest = json.loads((ROOT/'model/runtime_manifest.json').read_text())
selection = json.loads(Path('/data/athena-articulino-references-20261027/selection.json').read_text())
texts = {x['label']:x['text'] for x in json.loads((ROOT/'reference-texts.json').read_text())}
sessions = []
original_session = ort.InferenceSession
def audited_session(path, *args, **kwargs):
session = original_session(path, *args, **kwargs)
providers = session.get_providers()
assert providers == ['CPUExecutionProvider']
sessions.append(dict(file=Path(path).name, providers=providers))
return session
ort.InferenceSession = audited_session
registration = VoiceRegistration(ROOT/'model/registration', ROOT/'voices', manifest['model_fingerprint'])
assert registration.status()['available']
rows = []
for clip in selection['clips']:
label = clip['label']
source = REFS/clip['file']
data = source.read_bytes()
assert hashlib.sha256(data).hexdigest() == clip['sha256']
available = next(int(x.split()[1])*1024 for x in Path('/proc/meminfo').read_text().splitlines() if x.startswith('MemAvailable:'))
assert available > 6*1024**3, 'Own 4 GiB budget plus 2 GiB host reserve unavailable'
start = time.monotonic()
meta = registration.register(data, source.name, texts[label], 'anna-'+label)
row = dict(label=label, seconds=time.monotonic()-start, code_shape=meta['shape'],
source_sha256=meta['source_sha256'], source_sample_rate=meta['source_sample_rate'],
codec_sample_rate=meta['sample_rate'], peak_rss_kib=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
rows.append(row)
(ROOT/'registration-results.json').write_text(json.dumps(dict(rows=rows,sessions=sessions),indent=2))
print(json.dumps(row), flush=True)