# Builds what Splainer downloads for its local voice (Settings -> Voice -> Download), into tools\voice\build\release: # splainer-voice-win-x64.zip the voice server as a ready-made program (server\splainer-voice.exe), no Python needed # splainer-voice-gpu-win-x64.zip CUDA libraries so Whisper runs on an NVIDIA card (gpu\*.dll) # kokoro-v1.0.onnx, voices-v1.0.bin, whisper-small\*, whisper-large-v3-turbo\* the models, copied from -Models # manifest.json every file's size and SHA-256; paste the printed lines into LocalVoiceCatalog.cs # Needs uv (https://docs.astral.sh/uv/) on PATH. -Models is a folder that already holds the models, e.g. # %LOCALAPPDATA%\Splainer-Local\voice. Upload the release folder with publish_voice_hf.py. param([string]$Models = (Join-Path $env:LOCALAPPDATA 'Splainer-Local\voice'), [string]$Out = (Join-Path $PSScriptRoot 'build'), [switch]$SkipGpu) $ErrorActionPreference = 'Stop' Add-Type -AssemblyName System.IO.Compression.FileSystem $venv = Join-Path $Out 'env'; $python = Join-Path $venv 'Scripts\python.exe'; $release = Join-Path $Out 'release' New-Item -ItemType Directory -Force -Path $Out, $release | Out-Null if (-not (Test-Path $python)) { & uv venv $venv --python 3.12; if ($LASTEXITCODE -ne 0) { throw 'uv venv failed' } } & uv pip install --python $python -r (Join-Path $PSScriptRoot 'requirements.txt') pyinstaller==6.22.3 if ($LASTEXITCODE -ne 0) { throw 'installing the voice packages failed' } # 1. The server as a program. --noconsole: it runs hidden behind Splainer. The collected packages carry data files or DLLs # PyInstaller cannot see from imports (espeak-ng data, ONNX Runtime and CTranslate2 libraries, Whisper's VAD model, FFmpeg). $dist = Join-Path $Out 'dist' if (Test-Path $dist) { Remove-Item -Recurse -Force $dist } & $python -m PyInstaller --noconfirm --clean --noconsole --name splainer-voice --distpath $dist --workpath (Join-Path $Out 'work') --specpath $Out ` --collect-all kokoro_onnx --collect-all espeakng_loader --collect-all onnxruntime --collect-all ctranslate2 --collect-all faster_whisper --collect-all av ` --collect-data phonemizer --collect-data language_tags --collect-data csvw --collect-data segments --copy-metadata kokoro-onnx ` --exclude-module tkinter --exclude-module sounddevice (Join-Path $PSScriptRoot 'kokoro_server.py') if ($LASTEXITCODE -ne 0) { throw 'PyInstaller failed' } $server = Join-Path $Out 'stage-server\server' if (Test-Path (Split-Path $server)) { Remove-Item -Recurse -Force (Split-Path $server) } New-Item -ItemType Directory -Force -Path (Split-Path $server) | Out-Null Move-Item (Join-Path $dist 'splainer-voice') $server function Zip($folder, $name) { $zip = Join-Path $release $name; if (Test-Path $zip) { Remove-Item $zip } [IO.Compression.ZipFile]::CreateFromDirectory($folder, $zip, [IO.Compression.CompressionLevel]::Optimal, $false); $zip } Zip (Split-Path $server) 'splainer-voice-win-x64.zip' | Out-Null # 2. The GPU pack: only the DLLs, flattened into gpu\. if (-not $SkipGpu) { $src = Join-Path $Out 'gpu-src' & uv pip install --python $python --target $src --no-deps -r (Join-Path $PSScriptRoot 'requirements-gpu.txt') if ($LASTEXITCODE -ne 0) { throw 'downloading the CUDA libraries failed' } $gpu = Join-Path $Out 'stage-gpu\gpu' if (Test-Path (Split-Path $gpu)) { Remove-Item -Recurse -Force (Split-Path $gpu) } New-Item -ItemType Directory -Force -Path $gpu | Out-Null Get-ChildItem (Join-Path $src 'nvidia\*\bin\*.dll') | Where-Object { $_.Name -notmatch '^nvblas|\.alt\.dll$' } | Copy-Item -Destination $gpu Get-ChildItem (Join-Path $src 'nvidia\*\License.txt'), (Join-Path $src 'nvidia_*.dist-info\License.txt') -ErrorAction SilentlyContinue | ForEach-Object { Copy-Item $_.FullName (Join-Path $gpu ($_.Directory.Name + '-License.txt')) } Zip (Split-Path $gpu) 'splainer-voice-gpu-win-x64.zip' | Out-Null } # 3. The models, laid out as the server expects them next to itself. foreach ($file in 'kokoro-v1.0.onnx', 'voices-v1.0.bin') { Copy-Item (Join-Path $Models $file) $release -Force } foreach ($pair in @(@('whisper-small', 'models--Systran--faster-whisper-small'), @('whisper-large-v3-turbo', 'models--mobiuslabsgmbh--faster-whisper-large-v3-turbo'))) { $snapshot = Get-ChildItem (Join-Path $Models "whisper\$($pair[1])\snapshots") -Directory | Select-Object -First 1 if (-not $snapshot) { throw "Whisper model $($pair[0]) is not in $Models\whisper" } $target = Join-Path $release $pair[0]; New-Item -ItemType Directory -Force -Path $target | Out-Null Get-ChildItem $snapshot.FullName -File | ForEach-Object { Copy-Item $_.FullName $target -Force } # resolves the cache's links } # 4. Sizes and hashes. $files = Get-ChildItem $release -Recurse -File | Where-Object { $_.Name -ne 'manifest.json' } | ForEach-Object { [ordered]@{ path = $_.FullName.Substring($release.Length + 1).Replace('\', '/'); bytes = $_.Length; sha256 = (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant() } } $files | ConvertTo-Json | Set-Content (Join-Path $release 'manifest.json') -Encoding utf8 "`nLocalVoiceCatalog.cs entries:" $files | ForEach-Object { ' new("{0}",{1},"{2}"),' -f $_.path, $_.bytes, $_.sha256 } "`nRelease folder: $release"