Vocalizer: Local Text-to-Speech for PHP | Mohamed Said       [Skip to content](#main)  [ ![](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png) Mohamed SaidLaravel Backend Engineer ](https://www.msaied.com/public) - [Home](https://www.msaied.com/public)
- [Projects](https://www.msaied.com/public/projects)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [About](https://www.msaied.com/public#about)

           [  Contact](https://www.msaied.com/public#contact) Menu 

Menu
----

Close 

 - [HomeStart here](https://www.msaied.com/public)
- [ProjectsCase studies](https://www.msaied.com/public/projects)
- [ArticlesEngineering notes](https://www.msaied.com/public/articles)
- [CertificatesCredentials](https://www.msaied.com/public/certificates)
- [AboutHow I work](https://www.msaied.com/public#about)
- [ContactGet in touch](https://www.msaied.com/public#contact)

  [Start a conversation](https://www.msaied.com/public#contact) [WhatsApp](https://wa.me/201094619204) [Email](mailto:hello@msaied.com) 

 1. [Home](https://www.msaied.com/public)
2. /
3. [Articles](https://www.msaied.com/public/articles)
4. /
5. [Open Source](https://www.msaied.com/public/articles?category=open-source)
6. /
7. Vocalizer: Run Local Text-to-Speech in PHP with No API Calls

   [Open Source](https://www.msaied.com/public/articles?category=open-source) [PHP](https://www.msaied.com/public/articles?category=php) 

 Vocalizer: Run Local Text-to-Speech in PHP with No API Calls
=============================================================

 Vocalizer is a native PHP extension that runs text-to-speech synthesis entirely on-device. It supports eight model families, voice cloning, crash isolation, and async synthesis — no external API required.

 ![](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp) [Mohamed Said](https://www.msaied.com/public#person) Published 16 Jul 2026 · Updated 17 Jul 2026 · 3 min read

ShareCopy linkCopied

 ![Vocalizer: Run Local Text-to-Speech in PHP with No API Calls](https://cdn.msaied.com/437/12b1894dab8c3f08825306988f8c9fb7.png) 

  On this page +1. [What Is Vocalizer?](#what-is-vocalizer)
2. [Eight Model Families, One API](#eight-model-families-one-api)
3. [Voice Cloning with Chatterbox](#voice-cloning-with-chatterbox)
4. [Crash Isolation and Async Synthesis](#crash-isolation-and-async-synthesis)
5. [Installation](#installation)
6. [Key Takeaways](#key-takeaways)

 What Is Vocalizer?
------------------

Vocalizer is a native PHP extension by [Akram Zerarka](https://github.com/AkramZerarka) that brings local text-to-speech (TTS) synthesis to PHP applications. It embeds two inference backends — **sherpa-onnx** (ONNX Runtime) and **audio.cpp** (ggml) — and ships as a prebuilt `.so` binary for Linux x86-64. There is nothing to compile and no external API to call.

Eight Model Families, One API
-----------------------------

`Engine::load()` points at a model directory, auto-detects the backend from its contents, and exposes a single `speak()` call:

```php
use Vocalizer\Engine;

$engine = Engine::load('/opt/voices/sherpa-onnx-supertonic-3-tts-int8-2026-05-11');

$res = $engine->speak('Votre commande est prête.', [
    'lang'       => 'fr',
    'voice'      => 0,
    'speed'      => 1.0,
    'timeout_ms' => 30_000,
]);

$res->save('/var/www/audio/notice.wav');
echo $res->seconds, " s in ", $res->generationMs, " ms\n";

```

The supported model families and their trade-offs:

| Goal | Model | Latency (CPU) | |---|---|---| | Best realism, voice cloning | Chatterbox | Slow (~20× real time) | | Fast multi-language (31 languages) | Supertonic 3 | Real-time | | Lightweight FR/EN cloning | Pocket TTS | Fast | | Fastest, one model per locale | Piper/VITS | Very fast |

Voice Cloning with Chatterbox
-----------------------------

Chatterbox covers 23 languages with a single ~7.5 GB model and clones a voice from a 3–10 second reference WAV:

```php
$engine = Engine::load('/opt/voices/chatterbox', [
    'threads' => 4,
    'opts'    => ['weight_type' => 'f16'],
]);

$res = $engine->speak('Bonjour, votre commande est prête.', [
    'lang'      => 'fr',
    'reference' => '/opt/voices/refs/fr.wav',
    'opts'      => [
        'temperature'        => 0.6,
        'repetition_penalty' => 1.2,
        'seed'               => 42,
    ],
    'timeout_ms' => 600_000,
]);

```

Because autoregressive TTS models can skip text, loop, or produce silence, Vocalizer includes an **anti-hallucination guard**. Every Chatterbox output is checked against text length and signal energy. Suspicious audio is re-synthesized with a new seed (two extra attempts by default). If all attempts fail, a `Vocalizer\Exception` is thrown, making a fallback to a faster model straightforward:

```php
try {
    $res = $engine->speak($text, ['lang' => 'fr', 'reference' => $ref]);
} catch (\Vocalizer\Exception $e) {
    $res = Engine::load('/opt/voices/sherpa-onnx-supertonic-3-tts-int8-2026-05-11')
        ->speak($text, ['lang' => 'fr']);
}

```

Crash Isolation and Async Synthesis
-----------------------------------

Native inference engines can segfault. Vocalizer's default **fork isolation mode** runs synthesis in a child process, so a crash is caught, retried, and the model reloaded — surfacing as a `Vocalizer\CrashException` only when recovery fails. Chatterbox always runs in direct mode because its ggml thread pool is not fork-safe.

For longer texts, `speakAsync()` moves synthesis off the request path:

```php
$job = $engine->speakAsync($paragraph);
$res = $job->wait(30_000) ?? throw new RuntimeException('still running');

```

Key `php.ini` directives: `vocalizer.isolation`, `vocalizer.timeout_ms`, `vocalizer.max_models` (LRU model cache per worker), and `vocalizer.max_concurrency` for the async pool.

Installation
------------

Vocalizer requires **Linux x86-64**, glibc ≥ 2.28, and **PHP 8.4 or 8.5 NTS**. Alpine/musl, ARM, and ZTS builds are not supported.

```bash
curl -fsSL https://raw.githubusercontent.com/akramzerarka/vocalizer/main/install.sh | bash

```

Models are downloaded separately:

```bash
./scripts/download-model.sh chatterbox                                    # ~7.5 GB
./scripts/download-model.sh sherpa-onnx-supertonic-3-tts-int8-2026-05-11  # ~120 MB
./scripts/download-model.sh vits-piper-en_US-amy-low                      # ~65 MB

```

Key Takeaways
-------------

- Runs entirely on-device — no API keys, no network calls, no runtime dependencies to compile.
- Eight TTS model families auto-detected from a directory; one unified `speak()` API.
- Voice cloning from a short WAV reference via Chatterbox (23 languages, ~7.5 GB model).
- Anti-hallucination guard re-synthesizes suspicious output before throwing an exception.
- Fork isolation protects PHP-FPM workers from native engine crashes.
- `speakAsync()` keeps long synthesis jobs off the request path.
- Requires Linux x86-64, glibc ≥ 2.28, PHP 8.4/8.5 NTS; MIT-licensed.

---

*Source: [Vocalizer: Local Text-to-Speech for PHP — Laravel News](https://laravel-news.com/vocalizer-local-text-to-speech-for-php)*

- [text-to-speech](https://www.msaied.com/public/articles?search=text-to-speech)
- [PHP extension](https://www.msaied.com/public/articles?search=PHP%20extension)
- [voice cloning](https://www.msaied.com/public/articles?search=voice%20cloning)
- [TTS](https://www.msaied.com/public/articles?search=TTS)
- [local AI](https://www.msaied.com/public/articles?search=local%20AI)
- [NativePHP](https://www.msaied.com/public/articles?search=NativePHP)

 Frequently asked questions 
---------------------------

  Does Vocalizer require an external API or internet connection to synthesize speech?No. Vocalizer runs entirely on-device. It embeds the sherpa-onnx and audio.cpp inference backends directly in the PHP extension, so no API calls or network access are needed at synthesis time.

   Which PHP versions and operating systems does Vocalizer support?Vocalizer requires Linux x86-64 with glibc 2.28 or higher and PHP 8.4 or 8.5 NTS. Alpine/musl, ARM, and ZTS builds are not currently supported.

   What happens if a native inference engine crashes during synthesis?By default, Vocalizer runs synthesis in a forked child process. If the child crashes, it is retried and the model reloaded automatically. A Vocalizer\\CrashException is only thrown if recovery fails after the configured maximum retries.

   ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)About the author
----------------

[Mohamed Said](https://www.msaied.com/public#person)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

[About](https://www.msaied.com/public#about) [GitHub ↗](https://github.com/EG-Mohamed) [LinkedIn ↗](https://www.linkedin.com/in/msaiedm/) [WhatsApp ↗](https://wa.me/201094619204) [Email Address ↗](mailto:hello@msaied.com) [My CV ↗](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)  

   [Previous articleLivewire v3 Performance: Lazy Hydration, Computed Properties, and Minimising Wire Payloads](https://www.msaied.com/public/articles/livewire-v3-performance-lazy-hydration-computed-properties-and-minimising-wire-payloads) [Next articleEloquent Custom Casts: Encapsulating Value Objects Without the Bloat](https://www.msaied.com/public/articles/eloquent-custom-casts-encapsulating-value-objects-without-the-bloat-1)  

   On this page
-------------

1. [What Is Vocalizer?](#what-is-vocalizer)
2. [Eight Model Families, One API](#eight-model-families-one-api)
3. [Voice Cloning with Chatterbox](#voice-cloning-with-chatterbox)
4. [Crash Isolation and Async Synthesis](#crash-isolation-and-async-synthesis)
5. [Installation](#installation)
6. [Key Takeaways](#key-takeaways)

 ###  Have a technical challenge?

 Tell me what you’re building. I reply within two working days.

[Start a conversation](https://www.msaied.com/public#contact) 

   Related articles
-----------------

 [ ![](https://cdn.msaied.com/740/cce86edc21eddcbdd2f2454fadaf9c70.png)  · 3 min read### The Pipeline Pattern in Laravel: Custom Pipelines Beyond Middleware

5 Oct 2026 ](https://www.msaied.com/public/articles/the-pipeline-pattern-in-laravel-custom-pipelines-beyond-middleware-1) [ ![](https://cdn.msaied.com/739/2d6897fdcdcf090613f96f72a64b8a78.png)  · 4 min read### MySQL Full-Text Search in Laravel: Indexes, Relevance Scoring, and Boolean Mode

4 Oct 2026 ](https://www.msaied.com/public/articles/mysql-full-text-search-in-laravel-indexes-relevance-scoring-and-boolean-mode) [ ![](https://cdn.msaied.com/738/073696a3fefe18bec825beec5ac658f5.png)  · 4 min read### Laravel Queue Rate-Limited Middleware: Throttling Jobs Without Losing Work

4 Oct 2026 ](https://www.msaied.com/public/articles/laravel-queue-rate-limited-middleware-throttling-jobs-without-losing-work) 

  Have a technical challenge?
----------------------------

Tell me what you’re building. I reply within two working days.

 [Discuss your project ↗](https://www.msaied.com/public#contact) 

  © 2026 Mohamed Said · Built with Laravel, meant to last.Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

 - [Home](https://www.msaied.com/public)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [GitHub](https://github.com/EG-Mohamed)
- [LinkedIn](https://www.linkedin.com/in/msaiedm/)
- [WhatsApp](https://wa.me/201094619204)
- [Email Address](mailto:hello@msaied.com)
- [My CV](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
- [Sitemap](https://www.msaied.com/public/sitemap.xml)
