# Speech Swift

> An on-device speech AI toolkit for Mac and iOS — speech recognition, text-to-speech, speech-to-speech, VAD and diarization in native Swift on MLX and CoreML

- Category: Multimodal Generation / Audio, Music & Voice
- Language: Swift
- Licence: Apache-2.0
- Repository: https://github.com/soniqo/speech-swift
- Website: https://soniqo.audio
- Canonical page: https://ai-tldr.dev/tools/speech-swift/

## In short

Speech Swift is an on-device speech AI toolkit for Mac and iOS — speech recognition, text-to-speech, speech-to-speech, VAD and diarization in native Swift on MLX and CoreML. Model weights download from Hugging Face on first use and are cached locally, and every `fromPretrained()` entry point accepts an offline mode once the weights are cached. It sits in the Audio, Music & Voice category of the Multimodal Generation tools and is open-source, written in Swift and licensed Apache-2.0.

## Overview

Speech Swift is an open-source toolkit of AI speech models for Apple Silicon, built on MLX Swift and CoreML. It does speech recognition, synthesis and understanding on Mac and iOS entirely on the device — no cloud, no API keys, and no audio leaving the machine. Model weights download from Hugging Face on first use and are cached locally, and every `fromPretrained()` entry point accepts an offline mode once the weights are cached.

It ships as a Swift package where every model is its own SPM library, so an app imports only what it uses: Qwen3-ASR, WhisperASR, Parakeet, Nemotron Streaming and Omnilingual ASR for speech-to-text; Qwen3-TTS, CosyVoice, Kokoro, VibeVoice, Chatterbox and others for text-to-speech and voice cloning; PersonaPlex and VoiceChat for full-duplex speech-to-speech; plus Silero VAD, wake-word spotting, speaker diarization, speaker embeddings, noise suppression, echo cancellation, music source separation, text-to-music and on-device LLM chat and translation. Shared plumbing lives in `AudioCommon` and `MLXCommon`, and a `SpeechUI` module adds SwiftUI views for streaming transcripts.

Beyond the library, the same models are reachable from a `speech` command-line tool installed with Homebrew and from `speech-server`, a local HTTP and WebSocket server that exposes OpenAI-compatible `/v1/realtime` and `/v1/audio/transcriptions` endpoints. A `VoicePipeline` state machine wires any speech recognizer, speech generator and streaming VAD into a real-time ASR → LLM → TTS voice agent with turn detection and interruption handling. It requires Swift 6+, Xcode 16+, and macOS 15+ or iOS 18+ on Apple Silicon, and is licensed Apache 2.0.

## What it does

- One SPM library per model — import `ParakeetStreamingASR`, `Qwen3TTS` or `SpeechVAD` alone and pay for nothing else
- Speech-to-text across many engines, including streaming dictation with live partials and end-of-utterance detection, forced word-level alignment, and Omnilingual ASR covering 1,672 languages
- Text-to-speech with streaming, custom speakers and zero-shot voice cloning, from the 82M Kokoro model on the Neural Engine to long-form multi-speaker VibeVoice
- Full-duplex speech-to-speech (PersonaPlex, VoiceChat) and streaming speech-to-speech translation (Hibiki), plus a `VoicePipeline` for ASR → LLM → TTS voice agents
- Voice activity detection, end-of-turn detection, wake-word spotting, speaker diarization and speaker embeddings, plus noise suppression, speech restoration and echo cancellation
- A Homebrew `speech` CLI and a local `speech-server` with OpenAI-compatible Realtime WebSocket and transcription endpoints

## Getting started

Use it as a Swift package inside a Mac or iOS app, or install the command-line tool with Homebrew. Both need Apple Silicon with macOS 15+ (or iOS 18+); the Homebrew route requires native ARM Homebrew in /opt/homebrew.

1. Try it from the command line

   Install the CLI with Homebrew, then transcribe, speak or translate. `--engine` picks an alternative model.

```bash
brew install speech

speech transcribe recording.wav
speech transcribe recording.wav --engine voxtral
speech speak "Hello world"
speech translate "Hello, how are you?" --to es
```

2. Add the package to your app

   Add the dependency to Package.swift, then list only the model products you need — every model is its own SPM library.

```text
.package(url: "https://github.com/soniqo/speech-swift", branch: "main")

.product(name: "ParakeetStreamingASR", package: "speech-swift"),
.product(name: "SpeechUI",             package: "speech-swift"),  // optional SwiftUI views
```

3. Transcribe audio

   Load a model (weights download from Hugging Face on first use) and transcribe a buffer, or iterate a stream to get live partials.

```text
import ParakeetStreamingASR

let model = try await ParakeetStreamingASRModel.fromPretrained()
let text = try model.transcribeAudio(audioSamples, sampleRate: 16000)

for await partial in model.transcribeStream(audio: samples, sampleRate: 16000) {
    print(partial.isFinal ? "FINAL: \(partial.text)" : "... \(partial.text)")
}
```

4. Synthesize speech

   Generate audio from text with Qwen3-TTS and write it to a WAV file.

```text
import Qwen3TTS
import AudioCommon

let model = try await Qwen3TTSModel.fromPretrained()
let audio = model.synthesize(text: "Hello world", language: "english")
try WAVWriter.write(samples: audio, sampleRate: 24000, to: outputURL)
```

5. Serve models over HTTP

   Run the local server to expose every model over REST and WebSocket, including an OpenAI-compatible Realtime WebSocket at /v1/realtime and a transcription endpoint at /v1/audio/transcriptions.

```bash
speech-server --port 8080
```

6. Build from source

   `make build` compiles the Swift package and the MLX Metal shader library, which GPU inference needs — without it you get `Failed to load the default metallib` at runtime.

```bash
git clone https://github.com/soniqo/speech-swift
cd speech-swift
make build
```

## When to use it

- Add private, offline dictation or meeting transcription to a macOS or iOS app without sending audio to a cloud API
- Build a local voice agent on a Mac — VAD-driven turn detection, ASR, an on-device LLM and TTS — or a full-duplex speech-to-speech assistant
- Give an app on-device text-to-speech or voice cloning, from a small Neural Engine model on iPhone to long-form multi-speaker audio on a Mac
- Point existing OpenAI Realtime or transcription clients at a local `speech-server` instead of a hosted endpoint
