New Tool Radar

Local AI

How to Generate Speech with LocalAI’s Piper Text-to-Speech Voice

Download a Piper voice, extract it into LocalAI's models folder, and send text to the /tts endpoint with the piper backend to hear it spoken.

Schematic diagram with three steps: install a Piper voice from the Piper releases version 0.0.2 by extracting the archive into the models folder, send text to the /tts endpoint with the piper backend and the voice file as the model, then hear the spoken audio as a WAV file played with aplay on Linux.

Piper is a manual-install text-to-speech backend in LocalAI: you download a voice file yourself and point LocalAI at it, instead of installing a gallery model. This guide is Piper-only. It does not use the omnivoice-cpp gallery model — that is a separate backend with its own install, its own voices, and voice cloning — and it does not use the Voice Library. The LocalAI TTS API is compatible with the OpenAI TTS API and the ElevenLabs API, and the /tts endpoint returns an audio/wav file.

Download a Piper voice and extract it

To install the piper audio models manually:

  • Download Voices from the Piper releases page (v0.0.2).
  • Extract the .tar.tgz files (.onnx, .json) inside models.

LocalAI must be compiled with the GO_TAGS=tts flag for Piper to be available. The voice files land in the models folder as a pair: the .onnx voice model and its .json configuration file.

Send text to the Piper voice

To use the tts endpoint, run the following command. You can specify a backend with the backend parameter. For example, to use the piper backend:

curl http://localhost:8080/tts -H "Content-Type: application/json" -d '{
  "model":"it-riccardo_fasol-x-low.onnx",
  "backend": "piper",
  "input": "Ciao, sono Ettore"
}' | aplay

The docs’ example voice is Italian (it-riccardo_fasol-x-low.onnx) speaking “Ciao, sono Ettore”. The model name is the filename with the extension, and the model name is case sensitive — spell it exactly as the file is named. aplay is a Linux command; you can use other tools to play the audio file. To keep the audio instead of playing it straight away, save the reply to a file with --output speech.wav in place of the | aplay pipe: the /tts endpoint returns an audio/wav file.

Check the spoken audio

Play the file and listen for the sentence you sent. To see which named voices your installed text-to-speech models offer, use GET /v1/audio/voices:

curl http://localhost:8080/v1/audio/voices

LocalAI returns 404 when the requested model is not installed, so a 404 here means the model name is wrong or the model is not installed yet.

Try it: four checks from voice file to spoken audio

Check What you should see If you do not see it
Voice installed it-riccardo_fasol-x-low.onnx and its .json file inside the models folder Check the .tar.tgz was extracted inside models, with the .onnx and .json files together
Request sent A reply from /tts with backend: piper and the voice filename as the model Check the backend is spelled piper and LocalAI is running on localhost:8080
Name matches The model name is the filename with the extension, in the same case: it-riccardo_fasol-x-low.onnx The model name is case sensitive — check every letter against the filename
Audio plays aplay on Linux plays “Ciao, sono Ettore”, or the saved speech.wav opens and plays the sentence Check LocalAI was compiled with the GO_TAGS=tts flag if the Piper backend is not available at all, and use another audio player if aplay is missing — it is a Linux command

Expected result. We checked the LocalAI text to audio docs page, which gives the TTS API as compatible with the OpenAI TTS API and the ElevenLabs API, the /tts endpoint generating speech from text with input and model and returning an audio/wav file, the Piper manual install of downloading voices from the Piper releases page v0.0.2 and extracting the .tar.tgz files (.onnx, .json) inside models, the curl command to /tts with model it-riccardo_fasol-x-low.onnx, backend piper, and input “Ciao, sono Ettore” piped to aplay, the notes that aplay is a Linux command with other tools to play the audio file, that the model name is the filename with the extension, that the model name is case sensitive, and that LocalAI must be compiled with the GO_TAGS=tts flag, and the GET /v1/audio/voices endpoint listing named voices with a 404 when the requested model is not installed. We did not install LocalAI, download any voice, or generate any speech on this machine.

Limits

This guide covers Piper only, with its manual voice install. It is not the omnivoice-cpp gallery install: that backend has its own models, its own voices, voice cloning from reference audio, and voice design by attribute keywords — none of that is Piper. Piper voices are files you download and extract; there is no gallery install command for them, and LocalAI must be compiled with the GO_TAGS=tts flag. The model name is the voice filename with its extension, and it is case sensitive, so a renamed or mistyped file is not found. aplay is a Linux command, so use another audio player on other systems. We did not run any of this ourselves.

Sources

See all