#!/bin/bash
# Koldflux test for "Transcribe Spanish audio to text" (2026-11-17).
# Speech: 40 sentences of the FLEURS es_419 test split (Google, CC BY 4.0), read aloud by native speakers.
# Selection: first recording of every 8th sentence id, first 40 (sample.tsv holds the reference text of each).
# The LIVE tool https://koldflux.com/tools/audio/to-text is driven in headless Chromium (Playwright), one clip per page load,
# the transcript is read from the "Download .txt" button, and scored by wer.py. Needs: ffmpeg, python3 + numpy, node + playwright.
set -e
mkdir -p work/clips work/v results && cd work
# 1) download and pick the clips (see sample.tsv), convert to 16-bit mono WAV
curl -sL -o test.tar.gz https://huggingface.co/datasets/google/fleurs/resolve/main/data/es_419/audio/test.tar.gz
curl -sL -o test.tsv https://huggingface.co/datasets/google/fleurs/resolve/main/data/es_419/test.tsv
# (clips/c01.wav .. c40.wav are the files named in column 3 of sample.tsv, renamed in order and converted:  ffmpeg -i in.wav -ac 1 -c:a pcm_s16le clips/cNN.wav)
python3 ../mkvariants.py                               # noise at 10 dB and 0 dB SNR (fixed seed 20261117), 8 kHz mono Opus 6 kbps voice-note copy
cd ..
W=work
node asr-run.cjs base Spanish results/base_es_clean.json $W/clips/c*.wav
node asr-run.cjs tiny Spanish results/tiny_es_clean.json $W/clips/c*.wav
node asr-run.cjs base English results/base_en_wronglang.json $W/clips/c*.wav
node asr-run.cjs base Spanish results/base_es_snr10.json $W/v/c*_snr10.wav
node asr-run.cjs base Spanish results/base_es_snr0.json $W/v/c*_snr0.wav
node asr-run.cjs base Spanish results/base_es_voicenote.json $W/v/c*_voicenote.ogg
python3 wer.py results sample.tsv | tee test-results.txt
# SRT export check on clips c01..c05 joined into one 56.7 s file (known answer: 5 sentences)
ffmpeg -v error -y $(for i in 01 02 03 04 05; do echo -i $W/clips/c$i.wav; done) -filter_complex "[0][1][2][3][4]concat=n=5:v=0:a=1[a]" -map "[a]" -c:a pcm_s16le c01-05.wav
# (open /tools/audio/to-text, pick Spanish, drop c01-05.wav, click Download .srt  ->  out.srt)
python3 srt-check.py out.srt c01-05.wav | tee -a test-results.txt
