Text-To-Speech

For private, open source, text-to-speech follow these guidelines. A user inputs text and this kokoro docker app converts their text into audio via a compact, local, artificial neural network. The app verbalises the user's text with realistic speech patterns and natural cadence in a British accent.

Workflow summary

Start the local text-to-speech service by opening a terminal and running sudo kokoro.sh. Then launch Chromium to browse http://localhost:8880/web.

Kokoro text-to-speech

Private, local, open source, realistic, text-to-speech (TTS) 🖹🡒🗣

The Kokoro-FastAPI text-to-speech docker container will read text aloud to a user. A user inputs text and a local artificial neural network converts the user's text into audio with realistic speech patterns and natural cadence.

Set up

If not already installed, install docker.

Install Kokoro-FastAPI

For standard CPU inference (that works reliably on any system) run

sudo docker run -d \
  --name kokoro-tts \
  -p 8880:8880 \
  -e DEFAULT_VOICE=bf_emma \
  ghcr.io/remsky/kokoro-fastapi-cpu:latest

Test Kokoro-FastAPI

Run sudo docker ps --filter name=kokoro-tts expect "kokoro-tts" status of "Up..." where "ps" stands for "process status".

Run sudo docker logs kokoro-tts expect "Uvicorn running on..."

In a web browser visit:- http://localhost:8880/web for beta web interface, and http://localhost:8880/docs for Open-API docs, and http://localhost:8880/v1/audio/voices expect JSON listing available voices including "bf_emma" (where "bf" stands for British female).

Text-to-speech is available via the beta web interface at http://127.0.0.1:8880/web or http://0.0.0.0:8880/web or http://localhost:8880/web.

Script automation

Create a script to launch docker daemon and run the text-to-speech container sudo nano /usr/local/bin/kokoro.sh

Add the following code to "kokoro.sh"


#!/bin/bash

# Ensure the script is executed with root privileges
if [ "$EUID" -ne 0 ]; then
  echo "Error: This script must be run with elevated privileges: sudo kokoro.sh"
  exit 1
fi

echo "Starting Docker daemon..."
systemctl start docker

echo "Starting Kokoro TTS container..."
docker start kokoro-tts

echo "Kokoro TTS service is active and ready at http://localhost:8880/v1"

In the nano text editor, save the file by pressing Ctrl + O then Enter then Ctrl + X.

Make kokoro.sh executable with sudo chmod +x /usr/local/bin/kokoro.sh

The text-to-speech container can now be started with sudo kokoro.sh.

Stop container

Powering off with the kokoro docker container still running is safe, however a manual stop can be triggered by running sudo docker stop kokoro-tts.

Chromium

In Chromium bookmark http://localhost:8880/web.

Chromium reduces delays by streaming initial audio while later speech synthesis continues.

Fault finding

Determine if docker daemon is active with systemctl is-active docker

Determine if docker container "kokoro-tts" is up and running with sudo docker ps --filter name=kokoro-tts expect "kokoro-tts" status of "Up..." where ps stands for "process status".

References

Kokoro-FastAPI

FastAPI

Kokoro-TTS-model