Text to speech in PHP and WordPress, offline
PHP has no speech synthesis of its own, so most tutorials send your text to a cloud API and pay per character. For a site that wants a listen version of every article, spoken notifications or audio for a shop, that bill grows with every post, and every text leaves your server.
This guide shows how to call the free SuperClonica engine from PHP through a local HTTP server: natural voices, WAV files you keep, and no fee per request.
How PHP can speak
Generate audio once per version of a text and serve it as a file; do not synthesize on every page view.
- Cloud APIs: natural voices, but an account, a key, a bill per character and your text on their servers.
- SuperClonica: a local HTTP server next to your site, natural, character and custom voices, offline.
- Either way, PHP sends JSON and receives audio; only the address changes.
- It speaks 31 languages; Chinese is not supported yet.
Hear the voices free online
Before you write code, open the page of any voice, type a line of 30 to 100 characters, choose the language and press Voice it. In a few seconds you hear the voice your site could have, with no account.
Start the speech server
An NVIDIA graphics card makes it faster with the cuda image, but an ordinary processor is enough.
- Start the server on the same machine or a private one: docker run -d -p 8000:8000 -v superclonica-models:/models superclonica/superclonica:cpu.
- The first start downloads the Supertonic 3 model, about 385 MB, into the volume; GET /health tells you when it is ready.
- POST /synthesize takes JSON with text, voice, lang, seed and normalize, and answers with a 16-bit mono WAV.
- voice is a stock name from M1 to M5 and F1 to F5, or the decoded content of a voice file.
Call it from PHP
No extension is required beyond the standard functions: $voice = json_decode(file_get_contents('voice.json'), true); $body = json_encode(['text' => 'Hello from PHP!', 'voice' => $voice, 'lang' => 'en', 'seed' => 7]); $wav = file_get_contents('http://localhost:8000/synthesize', false, stream_context_create(['http' => ['method' => 'POST', 'header' => 'Content-Type: application/json', 'content' => $body]])); file_put_contents('hello.wav', $wav); The same request works with the cURL extension or an HTTP client library such as Guzzle. For a stock voice, pass 'voice' => 'F1' instead of the decoded file. Convert the WAV to MP3 with ffmpeg if you want smaller files for the web.
WordPress and production habits
In WordPress, generate the audio from a publish hook or a background job, store it in the uploads folder and attach it to the post, so visitors download a file instead of waiting for synthesis. Do not expose port 8000 to the internet: set SUPERCLONICA_API_KEY and send it as a Bearer token, or keep the server on localhost. Choose a neutral stock voice for publications, tell listeners the audio is generated, and keep the written article accessible.