45 lines
2.0 KiB
PowerShell
45 lines
2.0 KiB
PowerShell
# Stages the WER corpus for asr_bench: the first N LibriSpeech test-clean
|
|
# utterances as 16 kHz mono WAV + one reference .txt each, under bench-corpus\
|
|
# at the repo root (git-ignored — audio never enters the repo).
|
|
param([int]$Utterances = 30)
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
if (-not (Get-Command ffmpeg -ErrorAction SilentlyContinue)) {
|
|
throw "ffmpeg is required on PATH (same requirement as the app's Import feature)"
|
|
}
|
|
|
|
$repo = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
|
$corpus = Join-Path $repo "bench-corpus"
|
|
$cache = "$env:LOCALAPPDATA\WhispAssist\models\bench-cache"
|
|
New-Item -ItemType Directory -Force $corpus, $cache | Out-Null
|
|
|
|
$tarball = Join-Path $cache "test-clean.tar.gz"
|
|
if (-not (Test-Path $tarball)) {
|
|
Write-Output "downloading LibriSpeech test-clean (~346 MB)"
|
|
curl.exe -sL -o "$tarball.part" "https://www.openslr.org/resources/12/test-clean.tar.gz"
|
|
if ($LASTEXITCODE -ne 0) { throw "download failed ($LASTEXITCODE)" }
|
|
Move-Item -Force "$tarball.part" $tarball
|
|
}
|
|
$extracted = Join-Path $cache "LibriSpeech\test-clean"
|
|
if (-not (Test-Path $extracted)) {
|
|
Write-Output "extracting"
|
|
tar -xzf $tarball -C $cache
|
|
if ($LASTEXITCODE -ne 0) { throw "extract failed ($LASTEXITCODE)" }
|
|
}
|
|
|
|
$flacs = Get-ChildItem -Recurse -Filter *.flac $extracted | Sort-Object FullName |
|
|
Select-Object -First $Utterances
|
|
foreach ($f in $flacs) {
|
|
$name = $f.BaseName
|
|
$wav = Join-Path $corpus "$name.wav"
|
|
if (-not (Test-Path $wav)) {
|
|
ffmpeg -v error -y -i $f.FullName -ar 16000 -ac 1 $wav
|
|
if ($LASTEXITCODE -ne 0) { throw "ffmpeg failed on $name" }
|
|
}
|
|
$trans = Get-ChildItem -Path $f.DirectoryName -Filter *.trans.txt | Select-Object -First 1
|
|
$line = Get-Content $trans.FullName | Where-Object { $_.StartsWith("$name ") } | Select-Object -First 1
|
|
if (-not $line) { throw "no reference line for $name" }
|
|
Set-Content -Encoding utf8 -NoNewline (Join-Path $corpus "$name.txt") $line.Substring($name.Length + 1)
|
|
}
|
|
Write-Output "staged $($flacs.Count) utterances in $corpus"
|