MLX Audio Swift
repository·main·Indexed 20 days ago
https://github.com/blaizzy/mlx-audio-swiftA modular Swift SDK for audio processing optimized for Apple Silicon using the MLX framework. It supports Text-to-Speech (TTS), Speech-to-Text (STT), Voice Activity Detection (VAD), and Speaker Diarization. The SDK is split into specialized modules including MLXAudioCore, MLXAudioCodecs, MLXAudioTTS, MLXAudioSTT, MLXAudioVAD, MLXAudioSTS, and MLXAudioUI, and is optimized for macOS 14+ and iOS 17+.
What's inside MLX Audio Swift
- MLX Audio Swift is a modular Swift SDK designed for audio processing on Apple Silicon using the MLX framework. It is optimized for macOS 14+ and iOS 17+. The library is split into specialized modules so developers can import only the specific functionality they require (e.g., TTS, STT, or VAD), minimizing the footprint of their application.
Overview of Voxtral Mini 4B Realtime
mainVoxtral Mini 4B Realtime 2602 is a multilingual, realtime speech-transcription model. It supports 13 languages and is designed for low-latency applications such as voice assistants and live subtitling. It is available in various quantization levels (fp16, 6bit, and 4bit) via themlx-communityHugging Face repository.Use Echo TTS for diffusion-based text-to-speech and voice cloning
mainEcho TTS is a diffusion-based text-to-speech model that supports voice cloning using a short reference audio clip. You can use it via the command line or integrate it into Swift applications using the
MLXAudioTTSframework. The model requires a reference audio file to clone a specific voice.mlx-audio-swift-tts \ --model mlx-community/echo-tts-base \ --text "Hello from Echo TTS." \ --ref-audio speaker.wavUse SenseVoice for speech understanding
mainSenseVoice is a speech foundation model that provides multiple capabilities in a single model: Automatic Speech Recognition (ASR), Spoken Language Identification (LID), Speech Emotion Recognition (SER), and Audio Event Detection (AED). It is a non-autoregressive CTC model.
Supported Model:
mlx-community/SenseVoiceSmall
Identify spoken language with MLXAudioLID
mainMLXAudioLID provides Swift implementations of spoken language identification (LID) models. It can identify languages from raw audio waveforms using two primary model architectures:
Wav2Vec2ForSequenceClassification(MMS-LID-256) andEcapaTdnn(ECAPA-TDNN).Both models require 16 kHz mono audio. It is recommended to use
loadAudioArray(from:)fromMLXAudioCoreto handle automatic resampling.import MLXAudioCore import MLXAudioLID // Example using MMS-LID-256 let model = try await Wav2Vec2ForSequenceClassification.fromPretrained("facebook/mms-lid-256") let (_, audio) = try loadAudioArray(from: audioURL) let output = model.predict(waveform: audio, topK: 5) print("Language: \(output.language) (\(output.confidence * 100)%)")Use Pocket TTS for lightweight text-to-speech
mainPocket TTS is a lightweight text-to-speech (TTS) model from Kyutai optimized for efficient CPU execution. It can be used via the command line or integrated directly into Swift applications using theMLXAudioTTSframework.Use Marvis TTS for conversational text-to-speech
mainMarvis TTS is a fast conversational text-to-speech model that supports English, French, and German. It can be used via a Swift API or a Command Line Interface (CLI).Use Irodori TTS for Japanese Text-to-Speech
mainIrodori TTS is a Japanese flow-matching text-to-speech model (part of the Echo-TTS family). It uses a Rectified-Flow DiT over continuous latents at 48 kHz. A key feature is VoiceDesign, which allows you to describe a voice using a Japanese caption instead of providing a reference audio clip.
Key Characteristics
- Language: Japanese-only. Pass Japanese text directly.
- Voice Control: Use the
voiceparameter with a Japanese description (e.g., "a calm, natural female voice") to design the speaker's characteristics. - Model Weights: Available on Hugging Face (e.g.,
mlx-community/Irodori-TTS-600M-v3-VoiceDesign-8bit).
Overview of MOSS-TTS models
mainMOSS-TTS provides non-quantized full OpenMOSS text-to-speech capabilities. It utilizes a Qwen3 backbone, multi-codebook audio generation, and the MOSS Audio Tokenizer. The system supports three primary model variants:
- Standard Model: The base delay-pattern model.
- Dialogue Model: Optimized for multi-speaker dialogue.
- Local-Transformer Variant: A specific transformer-based architecture.
The
OpenMOSS-Team/MOSS-Audio-Tokenizeris automatically loaded as part of the process.Overview of Chatterbox TTS
mainChatterbox TTS is a two-stage speech synthesis system that supports voice cloning. It works by first converting text to speech tokens (T3) and then converting those tokens into 24kHz audio using S3Gen and HiFi-GAN.
There are two main variants:
- Regular: Uses LLaMA 520M, supports 23 languages, and includes emotion control.
- Turbo: Uses GPT-2 Medium, is English-only, and is optimized for faster generation.
Configure Temporal Anchors
mainTemporal anchors allow you to guide the separation by specifying when a target sound is or is not present. An anchor follows the format
(token: String, startTime: Float, endTime: Float).Token Meanings:
"+": The target sound is present during this time span."-": The target sound is NOT present during this time span.
Note: Anchors are currently not supported in chunked/long/streaming separation methods.
// Example: Target is present from 1.0s to 2.5s, and absent from 4.0s to 6.0s anchors: [[("+", 1.0, 2.5), ("-", 4.0, 6.0)]]How DeepFilterNet architecture works
mainDeepFilterNet uses a dual-pathway encoder-decoder architecture designed for real-time speech enhancement:
- ERB pathway (32 bands): Processes the broadband spectral envelope using 4 encoder convolution blocks, a squeezed GRU bottleneck, and 4 decoder transpose-convolution blocks. It outputs a per-band gain mask.
- DF pathway (96 bins): Processes the low-frequency complex spectrum using 2 encoder convolution blocks, a GRU, and a deep-filtering decoder. It outputs complex filter coefficients applied over a sliding window of
dfOrderframes. - Deep filtering: Applies learned complex FIR coefficients to the low-frequency spectrum for fine-grained noise suppression.
- Optimization: Recurrent layers use Accelerate-optimized CPU inference (
vDSP_mmul) with batch GPU input projection to avoid Metal kernel dispatch overhead in the sequential hidden-state loop.
Technical Specs:
- Input: 48kHz mono audio.
- Hop size: 480 samples (10ms).
- FFT size: 960.