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.1.tar.gz (26.1 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.1-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for smoltts_mlx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e3107b10483ada3adc82639e7dac6017c80ce89c81c50934e9cf0dba38afe04c
MD5 3a7361da0a950e98f3df769849a54c9c
BLAKE2b-256 e4a853d96470e70d4c27ca6a4744349c03691e5d0b2b9b6d63a11b7232ec8b1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for smoltts_mlx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2897eab7ee8f89c9c1c7b4379b92b87ee285bf71db5decc23181538fb524a535
MD5 a1d240328c328ffadb5866c1be4d3d20
BLAKE2b-256 e17167da49d72ea2785582744663d9e4540400c2b7091e50fbfd38d884770570

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