@suarify/kecil-tts

kecil tts 8M

Malay text to speech, fully on your device. No API key, no server.

🔒 Privacy - text stays on your device ⚡ Offline after first download 💨 ~8 MB, fast load 🇲🇾 Localised Bahasa Melayu Malaysia 🖥️ Runs on CPU / edge devices

Get started

npm i @suarify/kecil-tts
import { speak } from '@suarify/kecil-tts';

const { wav } = await speak('Assalamualaikum, selamat pagi.', { voice: 'yati' });
new Audio(URL.createObjectURL(new Blob([wav], { type: 'audio/wav' }))).play();

Try It

1 · Type your Text


2 · Choose Your Speaker

Effects same knobs as the HF Space

Code

Log
Available voices & versions

From listVoices() - the same speakers and versions as the Hugging Face Space.

Sample code - click to expand copy & try

Every snippet has a Try it button that runs it and prints the result in the log above.

Basic start - load + play with stream

Loads the default model on first use, streams Malay text, joins the PCM chunks and plays the result - the most common integration.

import { stream, concatFloat32, encodeWav, SAMPLE_RATE } from '@suarify/kecil-tts';

const chunks = [];
for await (const pcm of stream('Selamat pagi, boleh saya bantu?', { voice: 'yati' })) {
  chunks.push(pcm);
}
const audio = concatFloat32(chunks);
const wav = encodeWav(audio, SAMPLE_RATE);
new Audio(URL.createObjectURL(new Blob([wav], { type: 'audio/wav' }))).play();

listVoices() / listVersions()

Returns every speaker and published version so you can build voice/version selectors.

import { listVoices, listVersions } from '@suarify/kecil-tts';

const speakers = listVoices();
const yatiVersions = listVersions('yati');
const everyVersion = listVersions();

downloadWav()

Saves rendered audio as a .wav file from a browser.

import { speak, downloadWav } from '@suarify/kecil-tts';

const { wav } = await speak('Selamat pagi.');
downloadWav(wav, { filename: 'selamat-pagi.wav' });

loadTTS()

Initializes and caches a model instance for repeated synthesis.

import { loadTTS, VOICE_VERSIONS } from '@suarify/kecil-tts';

const tts = await loadTTS({
  voice: 'michael',
  version: VOICE_VERSIONS.michael[0].id,
  progressCallback: (p) => console.log(p.status, p.file),
});

speak()

Synthesizes a whole sentence at once and returns Float32 PCM plus a ready WAV.

import { speak } from '@suarify/kecil-tts';

const { audio, sampleRate, wav } = await speak('Selamat pagi.', {
  voice: 'nicole', version: 'v0.2 (latest)', speed: 1,
});

stream()

Yields audio piece by piece so playback can start before the whole sentence is rendered.

import { stream, SAMPLE_RATE } from '@suarify/kecil-tts';

for await (const pcm of stream('Assalamualaikum, ini ujian.', { voice: 'firdaus' })) {
  playChunk(pcm, SAMPLE_RATE);
}

speakPCM()

Collects a stream into raw Float32Array PCM without encoding a WAV.

import { speakPCM } from '@suarify/kecil-tts';

const { audio, sampleRate } = await speakPCM('Harganya RM12.50 ya.');

encodeWav() / concatFloat32()

Concatenates PCM chunks and encodes them as 16-bit mono WAV.

import { encodeWav, concatFloat32, SAMPLE_RATE } from '@suarify/kecil-tts';

const audio = concatFloat32([new Float32Array(24000), new Float32Array(12000)]);
const wav = encodeWav(audio, SAMPLE_RATE);

createG2P() / normalize()

Normalizes Malay text and converts it to phonemes and token ids (the model front end).

import { normalize, createG2P } from '@suarify/kecil-tts';

const text = normalize('Harga RM12.50, 3 hari lepas.');
const g2p = createG2P();
const phonemes = g2p.phonemize(text);
const ids = g2p.tokens(phonemes);

KecilTTS - lower-level class

Lower-level model class for direct control of phonemizing, synthesis and streaming.

import { KecilTTS } from '@suarify/kecil-tts';

const tts = await KecilTTS.load({ model: 'Suarify/kecil-tts-yati-v0.5.0' });
const { audio, sampleRate } = await tts.speak('Selamat malam.');

Node.js server-side

Server-side Node 20+ usage; writes the WAV with node:fs.

import { speak } from '@suarify/kecil-tts';
import { writeFileSync } from 'node:fs';

const { wav } = await speak('Assalamualaikum, selamat pagi.', { voice: 'yati' });
writeFileSync('out.wav', Buffer.from(wav));

applyEffects() - with live preview

Applies the HF Space effect chain - tone, exciter, doubling/chorus, echo, room and limiter - to raw PCM. speak() already applies effects; use speakPCM() when you want to apply them yourself.

import { speakPCM, applyEffects } from '@suarify/kecil-tts';

const { audio, sampleRate } = await speakPCM('Selamat malam.');
const shaped = applyEffects(audio, { sampleRate, effects: { preset: 'Warm + presence' } });

Press Try it to render the snippet and hear it here.

Use it in your project

Install the package and call speak. Or use the ONNX model in Python. No API key, no server.

npm (JS)

npm i @suarify/kecil-tts

import { speak } from '@suarify/kecil-tts';

const { wav } = await speak('Assalamualaikum, selamat pagi.', { voice: 'yati' });
new Audio(URL.createObjectURL(new Blob([wav], { type: 'audio/wav' }))).play();

Python (ONNX)

# Full runnable Python example (install, synth, WAV, streaming) is in the repo:
# https://github.com/suarify/kecil-tts-js/blob/main/sample/python/kecil_tts_example.py