Repository navigation
feat: add optional MLX Audio backend with model adapters - #58
Merged
Merged
Conversation
StuBehan
force-pushed
the
feat/mlx-backend
branch
from
September 25, 2026 10:34
983d35b to
97e4bcf
Compare
MLX binds GPU streams to threads, so a model loaded on one thread failed with "There is no Stream(gpu, 0) in current thread" when streaming playback or the daemon worker generated on another. Live `speak` and all daemon playback were broken; only `--out` worked. MlxBackend now owns a single daemon thread for load, reference decoding and generation. Also lower CHUNK_CHARS from 400 to 170: long prompts made autoregressive models skip or invent speech, losing a quarter to a third of the text in testing, while ~2-sentence chunks kept all of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StuBehan
force-pushed
the
feat/mlx-backend
branch
from
October 22, 2026 14:53
1e92e9d to
bed3c80
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
mlxbackend. On Apple Silicon it runs any text-to-speech model that MLX Audio can load from a local folder, including models that support voice cloning and style instructions. Kokoro (ONNX) stays the default, and nothing changes unless you pass--backend mlx.stackvox carries no model-specific code. Models that need special handling at load time (renamed weights, codec paths, tokenizer quirks) are handled by a model adapter: a small script the user writes and keeps locally. That keeps the core model-agnostic and keeps model licences out of stackvox. We never download, bundle or recommend a model.
Changes
stackvox/mlx_backend.pyloads a local model through MLX Audio and returns the same(samples, sample_rate)result as Kokoro.speakandservetake--backend {kokoro,mlx},--model-dirand--model-adapter.speak,sayandservetake--reference-audio,--reference-text,--instruct,--temperature,--top-pand--top-k.--model-adapter PATH(model_adapter=in Python) points at a script definingload(model_dir, load_model). It receives MLX Audio's loader and can patch, wrap or replace it.swapped()is public, so adapters can patch a class attribute and have it restored afterwards, even on error.serve --backend mlxkeeps the model loaded between requests. Generation options given toservebecome the defaults, and eachsayrequest can override them.MlxBackenddoes all MLX work (load, reference decoding, generation) on one dedicated thread. Without this, livespeakand daemon playback failed withThere is no Stream(gpu, 0) in current thread.--backend mlxare rejected:speakandservegive a usage error, and a Kokoro daemon replieserr:tosay. Previously they would have been silently dropped.ModelLoadErrorwith a one-line summary. When no adapter was used, the message suggests--model-adapter.stackvox[mlx]extra,mlx-audio>=0.4.5,<0.5, Apple Silicon only. The cap is there because MLX Audio is pre-1.0; the floor is the version verified end to end.NOTICEattributemlx-audio,mlx,mlx-lmandtransformers, and say that each model's own licence applies to its use.*.m4ais added to.gitignore.Testing
331 tests pass, and ruff, ruff format and mypy are clean. MLX Audio is mocked where it's imported, so CI doesn't need MLX installed. The new tests cover:
swapped()restoring attributesAlso run locally against a real model through an adapter:
speakplaybackservedaemon handling plain and voice-clonedsayrequests, pluscancelNotes
misaki. Some fetch assets by Hugging Face repo id even when loaded locally. The README mentions both, and these quirks are what adapters are for.--voiceand--langstill apply to Kokoro only. Mapping them onto each MLX model's own voice and language settings could be a follow-up.