Vocalizer: Local Text-to-Speech for PHP | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com) [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles  ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

  [ home ](https://msaied.com)    [ articles ](https://msaied.com/articles)    Vocalizer: Run Local Text-to-Speech in PHP with No API Calls        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)

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

 [  Open Source ](https://msaied.com/articles?category=open-source) [  PHP ](https://msaied.com/articles?category=php)  #text-to-speech   #PHP extension   #voice cloning   #TTS   #local AI   #NativePHP  

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

     16 Jul 2026      3 min read    ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said  

       Table of contents

1. [  01   What Is Vocalizer?  ](#what-is-vocalizer)
2. [  02   Eight Model Families, One API  ](#eight-model-families-one-api)
3. [  03   Voice Cloning with Chatterbox  ](#voice-cloning-with-chatterbox)
4. [  04   Crash Isolation and Async Synthesis  ](#crash-isolation-and-async-synthesis)
5. [  05   Installation  ](#installation)
6. [  06   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)*

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fvocalizer-run-local-text-to-speech-in-php-with-no-api-calls&text=Vocalizer%3A+Run+Local+Text-to-Speech+in+PHP+with+No+API+Calls) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fvocalizer-run-local-text-to-speech-in-php-with-no-api-calls) 

 Frequently Asked Questions 
----------------------------

  3 questions  

     Q01  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. 

      Q02  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. 

      Q03  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. 

  Continue reading

 More Articles 
---------------

 [ View all    ](https://msaied.com/articles) 

 [ ![Filament v4.12.1 Released: Field Wrapper Blade Component Alias Fix](https://cdn.msaied.com/436/aea645d1d73a84a3f29269b3e70f07d1.png) Filament Laravel Bug Fix 

### Filament v4.12.1 Released: Field Wrapper Blade Component Alias Fix

Filament v4.12.1 is a focused patch release that fixes an issue with Field wrapper Blade component aliases, en...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 17 Jul 2026     3 min read  

  Read    

 ](https://msaied.com/articles/filament-v4121-released-field-wrapper-blade-component-alias-fix) [ ![Advanced Authorization in Laravel: Gates, Policies, and Response-Based Access Control](https://cdn.msaied.com/435/961744168be44624c172aaf5623383f5.png) laravel authorization policies 

### Advanced Authorization in Laravel: Gates, Policies, and Response-Based Access Control

Go beyond simple boolean gates. Learn how to return rich authorization responses, compose policies with before...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 17 Jul 2026     3 min read  

  Read    

 ](https://msaied.com/articles/advanced-authorization-in-laravel-gates-policies-and-response-based-access-control-3) [ ![Eloquent Custom Casts: Encapsulating Value Objects Without the Bloat](https://cdn.msaied.com/434/ebfa76586107d613c3d3e65695f16ae4.png) laravel eloquent domain-driven-design 

### Eloquent Custom Casts: Encapsulating Value Objects Without the Bloat

Custom Eloquent casts let you map raw database columns directly to rich value objects. Learn how to build type...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 17 Jul 2026     1 min read  

  Read    

 ](https://msaied.com/articles/eloquent-custom-casts-encapsulating-value-objects-without-the-bloat-1) 

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

Explore

- [Home](https://msaied.com)
- [Projects](https://msaied.com/projects)
- [Articles](https://msaied.com/articles)
- [Certificates](https://msaied.com/certificates)
- [Contact](https://msaied.com#contact-section)

Connect

- [   hello@msaied.com ](mailto:hello@msaied.com)
- [   +20 109 461 9204 ](tel:+201094619204)

© 2026 Mohamed Said. All rights reserved.

 [  ](https://github.com/EG-Mohamed) [  ](https://www.linkedin.com/in/msaiedm/) [  ](https://wa.me/201094619204) [  ](mailto:hello@msaied.com) [  ](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
