Skip to main content

MLX inference for autoregressive speech models

Project description

smolltts-mlx

Installation

Requires working Python instance and Apple Silicon Mac.

pip install smoltts-mlx

Server

Startup

From the CLI, run:

smoltts-server

Options:

  • --port (optional): Port to listen on (default: 8000)
  • --config (optional): Point to a JSON file. (See below for spec)

Supported voices

As of February 2025, we support these voices from Kokoro:

  • American: heart (default), bella, nova, sky, sarah, michael, fenrir, liam
  • British: emma, isabella, fable

Voice cloning is currently not supported, but coming soon!

Unfortunately, GitHub doesn't support audio previews, but check out docs/examples for samples.

ElevenLabs endpoints

We support the following two ElevenLabs endpoints (more to come):

Here's an example with the Python SDK:

from elevenlabs.client import ElevenLabs

client = ElevenLabs(
    # or wherever you're running this on
    base_url="http://localhost:8000",
)

request_gen = client.text_to_speech.convert(
    voice_id="0",
    output_format="mp3_44100_128",
    text="You can turn on latency optimizations at some cost of quality. The best possible final latency varies by model.",
)

OpenAI endpoints

We support /v1/audio/speech (MP3 and WAV).

Here's an example with the OpenAI Python SDK:

from pathlib import Path
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000"
)

speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
    model="tts-1",
    voice="alloy",
    input="Today is a wonderful day to build something people love!",
)
response.stream_to_file(speech_file_path)

Configuration

Default settings are stored by default at ~/Library/Cache/smoltts.

You can also specify a JSON file with --config.

{
  // "checkpoint_dir": "../inits/foobar/"
  "model_id": "jkeisling/smoltts_v0",
  "generation": {
    "default_temp": 0.0,
    "default_fast_temp": 0.5,
    "min_p": 0.1
  },
  "model_type": {
    "family": "dual_ar",
    "codec": "mimi",
    "version": null
  }
}

Library

Basic Usage

from smoltts_mlx import SmolTTS
from IPython.display import Audio

# Initialize model (downloads weights automatically)
model = SmolTTS()

# Basic generation to numpy PCM array
pcm = model("Hello world!")
Audio(pcm, rate=model.sampling_rate)

# Streaming generation for real-time audio
for pcm_chunk in model.stream("This is a longer piece of text to stream."):
    # Yields 80ms PCM frames as they're generated
    process_audio(pcm_chunk)

Voice Selection

# Use a specific voice
pcm = model("Hello!", voice="af_bella")

# Create a custom voice from reference audio
speaker_prompt = model.create_speaker(
    system_prompt="<|speaker:0|>",
    samples=[{
        "text": "This is a sample sentence.",
        "audio": reference_audio  # Numpy array of PCM data
    }]
)

# Generate with custom voice
pcm = model(
    "Using a custom voice created from reference audio.",
    speaker_prompt=speaker_prompt
)

Working with Audio

The model works with raw PCM audio at 24kHz sample rate. For format conversion:

import soundfile as sf

# Save to WAV
sf.write("output.wav", pcm, model.sampling_rate)

# Load reference audio
audio, sr = sf.read("reference.wav")
if sr != model.sampling_rate:
    # Resample if needed
    audio = resampy.resample(audio, sr, model.sampling_rate)

Advanced Configuration

# Use custom model weights
model = SmolTTS(
    model_id="path/to/custom/model",
    checkpoint_dir="/path/to/local/weights"
)

# Access underlying components
mimi_codes = model.codec.encode(pcm)  # Work with Mimi tokens directly

Performance Notes

  • First generation may be slower due to model loading and warmup
  • Use streaming for longer texts to begin playback before full generation

Requirements

  • Apple Silicon Mac (M1/M2/M3)
  • Python 3.9 or later

Developing locally

Please use uv.

From the root of this repo:

uv sync --all-packages

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smoltts_mlx-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smoltts_mlx-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file smoltts_mlx-0.1.0.tar.gz.

File metadata

  • Download URL: smoltts_mlx-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.0

File hashes

Hashes for smoltts_mlx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0cceac32f094aa686283ad0884a09d6c13dc276754dc07d5c4f74a5bfbb17b52
MD5 4f56aecdee25faacfec1ead3e1d0f89f
BLAKE2b-256 4b58dc47dcadd04d5675c80471b382aa191bf6465f9bd7bb3372da37b2d97a58

See more details on using hashes here.

File details

Details for the file smoltts_mlx-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for smoltts_mlx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ad2a4af82f10cff3cba8d6f2b987d77ed71c8288f45a36b139a4dfd3506d0b1
MD5 9add93c5d079081bd2758901ac274a16
BLAKE2b-256 157d87202c6b41bb9ada6b255f10fb048a48da3cf1f312f5bcd876308aeeaf26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page