Skip to main content

Basic speech synthesis

The following talk.php demonstrates how to synthesize speech from text and write it to a WAV file.
PHP FFI is usually disabled in web server environments such as FPM. Run this script from the CLI with php talk.php.
Run it:

One-step synthesis with tts

If you want to skip the two-step createAudioQuery + synthesis flow, use the tts() method:

Synthesis from kana notation

You can also synthesize from AquesTalk-style kana notation:

Using a user dictionary

Use UserDict to register custom word pronunciations:

Adjusting AudioQuery

You can fine-tune the intonation and tempo by modifying the JSON returned by createAudioQuery before synthesis:

Retrieving accent phrases

You can retrieve and inspect accent phrase information for a text:

GPU mode

In environments where a GPU is available, specify AccelerationMode::Gpu for faster synthesis:

Using multiple voice models

Load multiple .vvm files and switch between style IDs to use different character voices:
To control what happens when a model with the same ID is already loaded, pass an OnExistingVoiceModelId as the second argument of loadVoiceModel(). The default Error throws an exception, Reload reloads the model and Skip does nothing:

Frame-based PCM rendering

Create an AudioFeature with createAudioFeature(), then slice() it by frame range and render() each slice to turn long text into audio piece by piece. This example writes PCM in chunks of about 0.3 seconds:
render() returns raw 16-bit PCM, not a WAV file. This path requires a VVM v2 model. The C API exposes AudioFeature creation and range rendering, but not the higher-level streaming_synthesis API.
Last modified on October 27, 2026