Skip to main content
Glama
README.md
# VoxLoom

[![CI](https://github.com/musbabaff/voxloom/actions/workflows/ci.yml/badge.svg)](https://github.com/musbabaff/voxloom/actions/workflows/ci.yml)
[![npm version](https://img.shields.io/npm/v/voxloom.svg)](https://www.npmjs.com/package/voxloom)
[![License: MIT](https://img.shields.io/badge/License-MIT-111316.svg)](./LICENSE)
[![Live Studio](https://img.shields.io/badge/Live_Studio-WebGPU_Demo-C93B14.svg)](https://musbabaff.github.io/voxloom/)

**Studio-realistic multilingual open-weight TTS engine, spoken-text prosody normalizer, `-16 LUFS` broadcast mastering DSP, OpenAI-compatible `/v1/audio/speech` server, CLI, and MCP stdio server.**

Built for developers who are tired of robotic browser `speechSynthesis` / `gTTS` voices and cloud per-character billing. Zero runtime npm dependencies, zero Python required, full TypeScript types, and first-class **Turkish + English + 35+ language** routing.

**[Try the live A/B Broadcast Audition Studio (WebGPU / WASM) →](https://musbabaff.github.io/voxloom/)**

![VoxLoom Studio Preview](./docs/og.png)

---

## Why default TTS sounds robotic (and how VoxLoom fixes it)

Most "AI voice" failures happen *before* and *after* the neural model:

1. **Raw symbols go straight to the model** (`₺1.250,50`, `14:30`, `%85`, `v2.4.1`, `Dr.`, Markdown links, URLs). VoxLoom normalizes raw text into natural spoken prose in Turkish and English while preserving explicit `[pause 350ms]` and `[breath]` cues.
2. **Long sentences wobble or rush.** VoxLoom splits input at abbreviation-safe sentence and clause boundaries with calibrated punctuation pause timing (`145 ms` clauses, `300 ms` sentences, `540 ms` paragraphs) and includes `createStreamingChunker()` for token-by-token LLM streams.
3. **Abrupt digital silence & erratic loudness.** Every chunk gets `8 ms` Hann raised-cosine edge fades, subtle `-62 dBFS` pink-filtered studio room tone during pauses, broadcast vocal EQ (`75 Hz` HPF, `2.8 kHz` presence, `7.2 kHz` de-esser), ITU-R BS.1770 K-weighted **`-16.0 LUFS`** normalization, and a **`-1.0 dBTP`** soft-knee peak limiter in pure TypeScript.

---

## Quick Start

### 1. CLI

```bash
# Inspect Turkish or English spoken-text normalization & prosody chunks (works offline, zero weights)
npx voxloom normalize "Dr. Ayşe 15.03.2026 saat 14:30 için ₺1.250,50 ve %85 indirim tanımladı." --lang tr

# List 65+ open-weight neural voices
npx voxloom voices
npx voxloom voices --lang tr

# Install optional local Kokoro-82M runtime (Apache-2.0, 54 voices across 8 languages)
npm install voxloom kokoro-js

# Synthesize -16 LUFS mastered WAV speech (supports voice blending!)
npx voxloom speak "Release v2.4.1 shipped at 19:05." --voice af_heart:0.65+af_bella:0.35 --out intro.wav

# Start a drop-in OpenAI-compatible speech server on localhost:8880
npx voxloom serve --port 8880
```

### 2. Drop-In OpenAI SDK Replacement

Keep your existing `openai` client code — just point `baseURL` at `voxloom serve`:

```ts
import OpenAI from "openai";
import { writeFileSync } from "node:fs";

const openai = new OpenAI({
  baseURL: "http://127.0.0.1:8880/v1",
  apiKey: "local-voxloom",
});

const speech = await openai.audio.speech.create({
  model: "tts-1",
  voice: "shimmer", // maps automatically to af_heart (or use tr_fahrettin, bf_emma, jf_alpha...)
  input: "Dr. Maya saved $1,250.50 at 19:05 with zero cloud voice fees.",
  response_format: "wav",
});

writeFileSync("studio.wav", Buffer.from(await speech.arrayBuffer()));
```

Every `POST /v1/audio/speech` response also exposes real mastering headers: `X-VoxLoom-Voice`, `X-VoxLoom-Lang`, `X-VoxLoom-Backend`, `X-VoxLoom-Lufs`, `X-VoxLoom-Peak-Db`, `X-VoxLoom-Duration-Sec`, and `X-VoxLoom-Elapsed-Ms`.

### 3. TypeScript SDK (Streaming, Dialogue & Pure DSP)

```ts
import { VoxLoom, createStreamingChunker, masterAudio } from "voxloom";
import { writeFileSync } from "node:fs";

const vox = new VoxLoom();

// Auto language detection + normalization + mastering
const res = await vox.speak({
  text: "Merhaba! [pause 350ms] Saat 14:30 itibarıyla ₺250 ödeme onaylandı.",
  lang: "tr",
});
writeFileSync("duyuru.wav", res.audio);
console.log(res.metrics); // { inputLufs, outputLufs: -16.0, peakDb: -1.0, durationSec }

// Multi-speaker podcast / dialogue rendering
const show = await vox.dialogue(
  `[Host]: Welcome to VoxLoom.
   [Guest]: Every sentence is normalized and mastered before output.`,
  { voices: { Host: "af_heart", Guest: "am_michael" } },
);
writeFileSync("dialogue.wav", show.audio);
```

### 4. Native Turkish & 35+ Languages (Piper VITS ONNX / Local GPU)

VoxLoom routes each voice to the best open-weight backend cleanly:

| Backend | Languages | Sample Rate | Runtime | License |
|---|---|---|---|---|
| **Kokoro-82M ONNX** (`kokoro-js`) | English (US/UK), Spanish, French, Italian, Portuguese, Japanese, Mandarin, Hindi (54 voices) | 24 kHz | Browser WebGPU/WASM & Node CPU | Apache-2.0 |
| **Piper VITS ONNX** (`piper`) | **Turkish** (`tr_fahrettin`, `tr_dfki`, `tr_fettah`), German, Arabic, Russian, Polish, Dutch, Ukrainian, Swedish, Persian, Vietnamese, Greek (35+ languages) | 22.05 kHz | Local CPU (`VOXLOOM_PIPER_DIR`) | MIT |
| **OpenAI-Compatible** (`--openai-url`) | Any model served by local **VoxCPM**, **Qwen3-TTS**, **Kikiri Turkish (`tf_nisan`)**, **Chatterbox**, or **Kokoro-FastAPI** | 24–48 kHz | Local GPU / HTTP | Upstream |
| **CustomBackend** | Any async `(params) => { samples, sampleRate }` function | Any | In-process | Your choice |

To run native Turkish locally with Piper:

1. Install the `piper` CLI binary from [rhasspy/piper](https://github.com/rhasspy/piper).
2. Download `tr_TR-fahrettin-medium.onnx` and `tr_TR-fahrettin-medium.onnx.json` from [rhasspy/piper-voices](https://huggingface.co/rhasspy/piper-voices) into `./models`.
3. Synthesize:

```bash
export VOXLOOM_PIPER_DIR=./models
npx voxloom speak "Merhaba! Saat 14:30 için ₺1.250,50 tutarındaki rapor %85 hızlandı." --lang tr --out tr.wav
```

### 5. MCP Server for AI Coding & Voice Agents

Add VoxLoom to Claude Desktop, Cursor, or any MCP-compatible client:

```json
{
  "mcpServers": {
    "voxloom": {
      "command": "npx",
      "args": ["-y", "voxloom", "mcp"]
    }
  }
}
```

Exposes 4 stdio JSON-RPC tools: `normalize_speech`, `list_voices`, `speak_text`, and `synthesize_dialogue`.

---

## Development

```bash
npm install
npm run verify   # strict tsc typecheck + build + node:test suite
```

See [CONTRIBUTING.md](./CONTRIBUTING.md) and the full [API & CLI Reference](https://musbabaff.github.io/voxloom/api.html).

## Credits & License

- **VoxLoom** is licensed under the [MIT License](./LICENSE).
- Open-weight models are downloaded or run by the user directly from their upstream projects:
  - [Kokoro-82M ONNX](https://huggingface.co/onnx-community/Kokoro-82M-v1.0-ONNX) (Apache-2.0)
  - [Piper Voices](https://huggingface.co/rhasspy/piper-voices) (MIT / upstream voice licenses)