voice-source-1: render script and clip builder
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8b9169e8c2
commit
11dec96d50
2 changed files with 48 additions and 0 deletions
28
tools/aqua-listen/kits/voice-source/clips.py
Normal file
28
tools/aqua-listen/kits/voice-source/clips.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Turns the six voice-source renders into the kit's clip files and measures them.
|
||||
clips.py <out-root> reads out/<label>/<label>.wav, writes clips/*.wav and measures.txt
|
||||
ros_matched is ros multiplied by (saw rms / ros rms) over the whole clip; every other clip is a byte copy of a render, and a clip used in two pairs is
|
||||
written once per pair under its own file name, so each pair is a unit the page can shuffle. Needs numpy."""
|
||||
import sys, wave, shutil, pathlib
|
||||
import numpy as np
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).parent))
|
||||
from hnr import read, hnr
|
||||
|
||||
out = pathlib.Path(sys.argv[1]); clips = out / "clips"; clips.mkdir(exist_ok=True)
|
||||
w = lambda n: out / "out" / n / f"{n}.wav"
|
||||
x = {n: read(str(w(n)))[0] for n in ["ref", "ros", "w20", "h20", "h25", "h15"]}
|
||||
rms = lambda a: float(np.sqrt(np.mean(a * a)))
|
||||
gain = rms(x["ref"]) / rms(x["ros"])
|
||||
with wave.open(str(w("ros"))) as src, wave.open(str(clips / "ros_matched.wav"), "wb") as dst:
|
||||
dst.setparams(src.getparams())
|
||||
dst.writeframes((np.clip(x["ros"] * gain, -1, 1) * 32767).astype("<i2").tobytes())
|
||||
files = {"saw_a.wav": "ref", "ros.wav": "ros", "saw_b.wav": "ref", "clean.wav": "ref", "w20.wav": "w20", "w20_b.wav": "w20", "h20.wav": "h20", "h25.wav": "h25", "h15.wav": "h15"}
|
||||
for f, n in files.items():
|
||||
shutil.copyfile(w(n), clips / f)
|
||||
lines = [f"{'clip':14s} {'HNR dB':>7s} {'rms':>8s} {'peak':>7s}"]
|
||||
for name in sorted(p.name for p in clips.glob("*.wav")):
|
||||
a, _ = read(str(clips / name))
|
||||
lines.append(f"{name:14s} {hnr(a, 48000)[0]:7.1f} {rms(a):8.4f} {np.abs(a).max():7.3f}")
|
||||
lines.append(f"ros_matched gain {gain:.3f} ({20 * np.log10(gain):.2f} dB)")
|
||||
(out / "measures.txt").write_text("\n".join(lines) + "\n")
|
||||
print("\n".join(lines))
|
||||
20
tools/aqua-listen/kits/voice-source/render.sh
Executable file
20
tools/aqua-listen/kits/voice-source/render.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
# Renders the voice-source-1 kit: the phrase /ɑmi/ (WordRender, 140 Hz, 48 kHz mono 16-bit), six renders that differ from the scaffold in ONE source field each:
|
||||
# ref (none) ros (pulse=rosenberg) w20 (noise=.33, white, HNR ~20) h20 (noise_hp=2000 noise=.33) h25 (noise_hp=2000 noise=.165) h15 (noise_hp=2000 noise=.6)
|
||||
# then ros_matched: ros scaled by the measured output-rms ratio saw/rosenberg, so a pair can be heard without the level difference.
|
||||
# render.sh <repo-root> <out-root> [jobs]
|
||||
# Needs CULTLIB_ROOT at the admitted CultLib revision and AQUASYNTH_FAUST_HOME. Under load each render is minutes (a Faust compile).
|
||||
# <out-root>/out/<label>/<label>.wav <out-root>/clips/*.wav the files kit.json names <out-root>/measures.txt HNR, rms, peak per clip
|
||||
# Build the page: node tools/aqua-listen/build.mjs --manifest tools/aqua-listen/kits/voice-source/kit.json --clips <out-root>/clips --out <out-root>/dist
|
||||
set -eu
|
||||
REPO=$(cd "$1" && pwd); OUT=$2; JOBS=${3:-6}; HERE=$REPO/tools/aqua-listen/kits/voice-source
|
||||
PY=${PYTHON:-python3}
|
||||
dotnet build "$REPO/tools/WordRender" -c Release -v q -o "$OUT/wr" | grep -E "rror\(s\)"
|
||||
mkdir -p "$OUT/out" "$OUT/clips"
|
||||
job() { n=$1; shift; dotnet "$OUT/wr/WordRender.dll" "$OUT/out/$n" "$n" 140 "$HERE/phones/ami.json" --source "$*" > "$OUT/out/$n.log" 2>&1 && echo "$n ok" || echo "$n FAILED (see $OUT/out/$n.log)"; }
|
||||
export -f job; export OUT HERE
|
||||
{
|
||||
echo "ref noise=.05"; echo "ros pulse=rosenberg"; echo "w20 noise=.33"
|
||||
echo "h20 noise_hp=2000 noise=.33"; echo "h25 noise_hp=2000 noise=.165"; echo "h15 noise_hp=2000 noise=.6"
|
||||
} | xargs -P "$JOBS" -L1 bash -c 'job "$@"' _
|
||||
$PY -I "$HERE/clips.py" "$OUT"
|
||||
Loading…
Reference in a new issue