Skip to content

Replace AudioSR with in-app VoiceFixer (ONNX Runtime) - #13

Open
bubio wants to merge 14 commits into
mainfrom
feature/voicefixer-onnx
Open

bubio wants to merge 14 commits into
mainfrom
feature/voicefixer-onnx

Conversation

@bubio

@bubio bubio commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Replaces AudioSR (Python, too slow) with VoiceFixer running in-app through ONNX Runtime. No Python setup is required. The spec is in docs/super-resolution.md.

Changes

  • Model: VoiceFixer is exported to three ONNX graphs (tools/voicefixer_onnx/export.py). Below 4.8kHz the output is replaced with the original audio, because VoiceFixer's resynthesis dropped Japanese consonants and attacks.
  • Runtime: Dart calls the ONNX Runtime 1.23.2 C API through ffigen bindings. hook/build.dart downloads the official archive for the target OS and CPU, checks its SHA-256 and bundles it as a native asset.
  • Build: inference runs in an isolate. Results are cached by input SHA-256 and can be cancelled. AudioSR code, gain 2.0 and the resume dialog are removed.
  • Settings: a VoiceFixer checkbox, plus a model download (430 MB) from the model-data-voicefixer-1 pre-release that can resume and checks SHA-256.
  • Licenses: VoiceFixer (MIT code, CC BY 4.0 weights) and ONNX Runtime with its third-party notices.
  • Google Colab backend: export writes the voices not yet cached to sr_input.zip. The notebook colab/super_resolution.ipynb runs the same models with onnxruntime-gpu and returns sr_output.zip. Import checks the model ID and puts the results in the cache. With this backend the build uses only cached results and needs no local model.
  • Workflows: the 5 build workflows run only for v* release tags, so model-data releases don't build the app.

Testing

  • On M4 macOS, a full STREAM5 build (732 files, about 2 hours of audio) took 63 minutes and wrote 44.1kHz WAVs. This is test/services/super_resolution_build_test.dart and runs only when VOICEFIXER_MODEL_DIR is set.
  • On macOS, integration_test/super_resolution_flow_test.dart runs with --dart-define=SR_E2E=true. It downloads the model from the settings dialog, enables super-resolution, builds, and checks the output is 44.1kHz.
  • CI checks the bundled ORT on macOS, Linux and Windows with integration_test/onnx_runtime_test.dart, which runs a small model that contains no weights. All three pass. Integration test files now run one per invocation, because on desktop a second file in the same run fails to start the app.
  • All 5 build workflows (macOS universal, Linux x64/arm64, Windows x64/arm64) were run with workflow_dispatch on this branch and succeeded.
  • Colab: run locally on CPU, the notebook's output was bit-identical (16-bit) to pipeline.py on 3 real voices, including one over 30 s. The app imported that sr_output.zip. Unit tests cover export, then import, then building with the Colab backend.

Not covered

  • Full-size inference speed and memory on Windows and Linux.
  • Running the notebook on a real Colab GPU. The app links to the notebook at tag v<version>, so the link works only after the next release.

🤖 Generated with Claude Code

bubio and others added 14 commits November 1, 2026 18:04
AudioSR was too slow to be practical, so the spec replaces it with
VoiceFixer exported to ONNX and run in-app through ONNX Runtime, which
means end users don't need a Python environment.

tools/voicefixer_onnx/export.py writes the three graphs (front with
soxr_hq-equivalent 4x upsampling and the GRU denoiser, back with the
UNet and vocoder, post that keeps the original audio below 4.8kHz).
pipeline.py is the reference implementation for the Dart port: it
chunks long files with context so the output matches whole-file
inference without crossfading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Vendor the ONNX Runtime 1.23.2 C API headers and generate dart:ffi
bindings with ffigen (only OrtGetApiBase and the OrtApi function table
are needed). OnnxRuntime/OrtModel wrap environment, session and tensor
handling, and VoiceFixer ports restore() from pipeline.py.

tool/voicefixer_cli.dart runs one WAV file; its output is bit-identical
to the Python reference on 8.9s and 36.4s (chunked) inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hook/build.dart downloads the official ONNX Runtime 1.23.2 release
archive for the target OS/architecture (macOS, Linux and Windows on
x64 and arm64), verifies its pinned SHA-256 and registers the library
as a code asset, so Flutter bundles it on every desktop platform
without touching the Xcode project or the CMake files. The archive is
cached across builds, and the onnxruntime_library user define allows
offline builds.

The bindings are now @Native externals resolved through that asset, so
OnnxRuntime no longer takes a library path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The super-resolution step now runs VoiceFixer through ONNX Runtime in a
background isolate instead of spawning the audiosr executable. Results
are cached by the input file's SHA-256, so files shared between streams
and work finished before a cancelled build are reused; cancelling stops
the current model run within milliseconds and leaves no partial cache
entry. The AudioSR-specific gain of 2.0 is dropped.

The settings dialog replaces the AudioSR options with a VoiceFixer
checkbox and a model download (resumable, SHA-256 checked) from the
model-data-voicefixer-1 pre-release. The "previous data found" dialog is
gone because the content-keyed cache is always safe to reuse.

The app build workflows now skip releases whose tag does not start
with "v", so publishing the model-data release does not attach app
binaries to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The license page now lists VoiceFixer (MIT code, CC BY 4.0 weights) and
ONNX Runtime with its third-party notices. The opt-in integration test
downloads the model from the settings dialog, enables super-resolution
and checks the build writes 44.1kHz audio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runs the weight-free vf_post.onnx through the ONNX Runtime library the
build hook bundles, so the e2e CI job checks the native asset on macOS,
Linux and Windows without downloading the model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On desktop, flutter test fails to start the app for the second file of
a multi-file integration test run, so loop over the files instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Export writes the voices that still need super-resolution to
sr_input.zip in the output folder. The notebook (colab/
super_resolution.ipynb) runs the same ONNX models with onnxruntime-gpu
and returns sr_output.zip, which import copies into the cache keyed by
input hash. With the Colab backend the build only uses cached results
and needs no local model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Colab has no API for running a notebook from another app, so the user
has to move zips through the browser. In Colab mode the build button is
replaced by three steps (export, open Colab, import and build) that show
what is done and what to do next. The downloaded sr_output.zip is found
in Downloads when the window regains focus, and importing it starts the
build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In Colab mode the main button becomes "Enhance on Colab and build…" and
opens a three-page dialog (export, run the notebook, import and build)
that starts at the first unfinished step. The step panel is kept on the
feature/colab-step-panel branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ONNX Runtime 1.23 is built for cuDNN 9.8. With the cuDNN 9.27 that Colab
now ships, a vocoder Conv failed with CUDNN_FE HEURISTIC_QUERY_FAILED and
ONNX Runtime silently fell back to the CPU, which takes hours. Install
the matching cuDNN, disable the CPU fallback, and check the GPU with a
short run before processing so a failure is reported at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Voices have different lengths, so the CUDA arena kept growing with new
buffer sizes until a T4 ran out of memory after about 150 files. Extend
the arena by exactly the requested size and shrink it after each run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Re-running the setup cell in the same runtime created new sessions while
the old ones still held the GPU memory, so cublasCreate failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant