@mlx-node/tts

Text to speech with Qwen3-TTS, streamed while it is generated.

Install

bash
npm install @mlx-node/tts

Get a model

bash
mlx download model -m Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice

Speak to a file

ts
import { homedir } from 'node:os';
import { join } from 'node:path';

import { loadTtsModel, WavWriter } from '@mlx-node/tts';

const models = join(homedir(), '.mlx-node', 'models');
const model = await loadTtsModel(join(models, 'qwen3-tts-12hz-0.6b-customvoice'));
const wav = await WavWriter.open('hello.wav', model.capabilities.sampleRate);
try {
  const speech = model.synthesizeStream('Hello from mlx-node.', { voice: 'vivian' });
  for await (const chunk of speech) {
    await wav.write(chunk);
  }
} finally {
  await wav.close();
  await model.dispose();
}

synthesizeStream yields audio chunks while the model is still generating. WavWriter writes them to a file.

Play it

createAudioPlayer(sampleRate) opens the speakers. Write the samples of each chunk to it. Playback needs macOS.

Voices

  • CustomVoice models come with preset voices, which model.capabilities.voices lists. Pick one with voice.
  • Base models clone a voice from a short reference recording and its transcript. Prepare it once with prepareVoice, then pass the voice it returns as voice.
  • The 1.7B VoiceDesign model takes a description of the voice.

A model keeps at most eight prepared voices.

From the terminal

bash
mlx tts -m ~/.mlx-node/models/qwen3-tts-12hz-0.6b-customvoice \
  --voice vivian --text "Hello from mlx-node." --play

mlx tts reads text from --text, --file or stdin. It needs -m, one voice (--voice, --reference-audio or --voice-description) and at least one of --play and -o: --play plays the speech, -o writes a WAV file.

Main exports

Name What it is
loadTtsModel(path) Load a Qwen3-TTS model
WavWriter, WavReader, readWav Read and write WAV files
createAudioPlayer(sampleRate) Play audio on the speakers (macOS)

Go deeper