MLX Audio Swift

repository·main·Indexed 20 days ago

https://github.com/blaizzy/mlx-audio-swift

A 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+.

Tokens
43.2K
Snippets
142
Records
190
Agent score
71%

What's inside MLX Audio Swift

  1. Overview of MLX Audio Swift

    main
    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.
  2. Use Echo TTS for diffusion-based text-to-speech and voice cloning

    main

    Echo 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 MLXAudioTTS framework. 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.wav
  3. Identify spoken language with MLXAudioLID

    main

    MLXAudioLID 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) and EcapaTdnn (ECAPA-TDNN).

    Both models require 16 kHz mono audio. It is recommended to use loadAudioArray(from:) from MLXAudioCore to 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)%)")
  4. Use Irodori TTS for Japanese Text-to-Speech

    main

    Irodori 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 voice parameter 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).
  5. Overview of MOSS-TTS models

    main

    MOSS-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:

    1. Standard Model: The base delay-pattern model.
    2. Dialogue Model: Optimized for multi-speaker dialogue.
    3. Local-Transformer Variant: A specific transformer-based architecture.

    The OpenMOSS-Team/MOSS-Audio-Tokenizer is automatically loaded as part of the process.

  6. Overview of Chatterbox TTS

    main

    Chatterbox 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.
  7. Configure Temporal Anchors

    main

    Temporal 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)]]
  8. How DeepFilterNet architecture works

    main

    DeepFilterNet 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 dfOrder frames.
    • 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.