Kevin200599 commited on
Commit
7fbd224
·
verified ·
1 Parent(s): 736dbe2

Source of the voice program

Browse files
Files changed (1) hide show
  1. source/build.ps1 +65 -0
source/build.ps1 ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Builds what Splainer downloads for its local voice (Settings -> Voice -> Download), into tools\voice\build\release:
2
+ # splainer-voice-win-x64.zip the voice server as a ready-made program (server\splainer-voice.exe), no Python needed
3
+ # splainer-voice-gpu-win-x64.zip CUDA libraries so Whisper runs on an NVIDIA card (gpu\*.dll)
4
+ # kokoro-v1.0.onnx, voices-v1.0.bin, whisper-small\*, whisper-large-v3-turbo\* the models, copied from -Models
5
+ # manifest.json every file's size and SHA-256; paste the printed lines into LocalVoiceCatalog.cs
6
+ # Needs uv (https://docs.astral.sh/uv/) on PATH. -Models is a folder that already holds the models, e.g.
7
+ # %LOCALAPPDATA%\Splainer-Local\voice. Upload the release folder with publish_voice_hf.py.
8
+ param([string]$Models = (Join-Path $env:LOCALAPPDATA 'Splainer-Local\voice'), [string]$Out = (Join-Path $PSScriptRoot 'build'), [switch]$SkipGpu)
9
+ $ErrorActionPreference = 'Stop'
10
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
11
+ $venv = Join-Path $Out 'env'; $python = Join-Path $venv 'Scripts\python.exe'; $release = Join-Path $Out 'release'
12
+ New-Item -ItemType Directory -Force -Path $Out, $release | Out-Null
13
+ if (-not (Test-Path $python)) { & uv venv $venv --python 3.12; if ($LASTEXITCODE -ne 0) { throw 'uv venv failed' } }
14
+ & uv pip install --python $python -r (Join-Path $PSScriptRoot 'requirements.txt') pyinstaller==6.22.3
15
+ if ($LASTEXITCODE -ne 0) { throw 'installing the voice packages failed' }
16
+
17
+ # 1. The server as a program. --noconsole: it runs hidden behind Splainer. The collected packages carry data files or DLLs
18
+ # PyInstaller cannot see from imports (espeak-ng data, ONNX Runtime and CTranslate2 libraries, Whisper's VAD model, FFmpeg).
19
+ $dist = Join-Path $Out 'dist'
20
+ if (Test-Path $dist) { Remove-Item -Recurse -Force $dist }
21
+ & $python -m PyInstaller --noconfirm --clean --noconsole --name splainer-voice --distpath $dist --workpath (Join-Path $Out 'work') --specpath $Out `
22
+ --collect-all kokoro_onnx --collect-all espeakng_loader --collect-all onnxruntime --collect-all ctranslate2 --collect-all faster_whisper --collect-all av `
23
+ --collect-data phonemizer --collect-data language_tags --collect-data csvw --collect-data segments --copy-metadata kokoro-onnx `
24
+ --exclude-module tkinter --exclude-module sounddevice (Join-Path $PSScriptRoot 'kokoro_server.py')
25
+ if ($LASTEXITCODE -ne 0) { throw 'PyInstaller failed' }
26
+ $server = Join-Path $Out 'stage-server\server'
27
+ if (Test-Path (Split-Path $server)) { Remove-Item -Recurse -Force (Split-Path $server) }
28
+ New-Item -ItemType Directory -Force -Path (Split-Path $server) | Out-Null
29
+ Move-Item (Join-Path $dist 'splainer-voice') $server
30
+ function Zip($folder, $name) {
31
+ $zip = Join-Path $release $name; if (Test-Path $zip) { Remove-Item $zip }
32
+ [IO.Compression.ZipFile]::CreateFromDirectory($folder, $zip, [IO.Compression.CompressionLevel]::Optimal, $false); $zip
33
+ }
34
+ Zip (Split-Path $server) 'splainer-voice-win-x64.zip' | Out-Null
35
+
36
+ # 2. The GPU pack: only the DLLs, flattened into gpu\.
37
+ if (-not $SkipGpu) {
38
+ $src = Join-Path $Out 'gpu-src'
39
+ & uv pip install --python $python --target $src --no-deps -r (Join-Path $PSScriptRoot 'requirements-gpu.txt')
40
+ if ($LASTEXITCODE -ne 0) { throw 'downloading the CUDA libraries failed' }
41
+ $gpu = Join-Path $Out 'stage-gpu\gpu'
42
+ if (Test-Path (Split-Path $gpu)) { Remove-Item -Recurse -Force (Split-Path $gpu) }
43
+ New-Item -ItemType Directory -Force -Path $gpu | Out-Null
44
+ Get-ChildItem (Join-Path $src 'nvidia\*\bin\*.dll') | Where-Object { $_.Name -notmatch '^nvblas|\.alt\.dll$' } | Copy-Item -Destination $gpu
45
+ 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')) }
46
+ Zip (Split-Path $gpu) 'splainer-voice-gpu-win-x64.zip' | Out-Null
47
+ }
48
+
49
+ # 3. The models, laid out as the server expects them next to itself.
50
+ foreach ($file in 'kokoro-v1.0.onnx', 'voices-v1.0.bin') { Copy-Item (Join-Path $Models $file) $release -Force }
51
+ foreach ($pair in @(@('whisper-small', 'models--Systran--faster-whisper-small'), @('whisper-large-v3-turbo', 'models--mobiuslabsgmbh--faster-whisper-large-v3-turbo'))) {
52
+ $snapshot = Get-ChildItem (Join-Path $Models "whisper\$($pair[1])\snapshots") -Directory | Select-Object -First 1
53
+ if (-not $snapshot) { throw "Whisper model $($pair[0]) is not in $Models\whisper" }
54
+ $target = Join-Path $release $pair[0]; New-Item -ItemType Directory -Force -Path $target | Out-Null
55
+ Get-ChildItem $snapshot.FullName -File | ForEach-Object { Copy-Item $_.FullName $target -Force } # resolves the cache's links
56
+ }
57
+
58
+ # 4. Sizes and hashes.
59
+ $files = Get-ChildItem $release -Recurse -File | Where-Object { $_.Name -ne 'manifest.json' } | ForEach-Object {
60
+ [ordered]@{ path = $_.FullName.Substring($release.Length + 1).Replace('\', '/'); bytes = $_.Length; sha256 = (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant() }
61
+ }
62
+ $files | ConvertTo-Json | Set-Content (Join-Path $release 'manifest.json') -Encoding utf8
63
+ "`nLocalVoiceCatalog.cs entries:"
64
+ $files | ForEach-Object { ' new("{0}",{1},"{2}"),' -f $_.path, $_.bytes, $_.sha256 }
65
+ "`nRelease folder: $release"