Console/terminal demo of text-to-speech with the pyttsx3 library, supporting Windows 11 and Ubuntu Linux 24.04. It speaks a text file (data/input.txt by default) line by line through the system speech engine, fully offline with no internet needed. The speech rate and the volume are lowered slightly by default (rate -30 words per minute, volume -0.25). Use --text to speak a string directly, or --save-wav to write the speech to an audio file instead of playing it.
About the speech engines: Windows uses the built-in SAPI5 voices, while Ubuntu needs eSpeak NG installed first (sudo apt install espeak-ng).
[Folder Structure]
- CLAUDE.md / AGENT.md: program specification (identical content).
- CHANGELOG.md: change log.
- copyright.txt: copyright notice.
- data/input.txt: the example text, an English paragraph.
- model/audio/: where the output files from --save-wav are written.
- tool/tools.py: shared helpers.
- src/: the demo, the launcher scripts and this document.
- venv/: Python virtual environment, created by step 1.
[Prerequisites]
- Operating system: Windows 11 or Ubuntu Linux 24.04.
- Python 3 and pip.
- A speech engine: Windows uses the built-in SAPI5, and Ubuntu needs eSpeak NG installed first.
- The dependency (pyttsx3) is listed in src/requirements.txt and installed by step 1.
- No internet and no GPU required.
[Instructions]
Step 1: create the virtual environment
Delete the old venv/, create a fresh one and install src/requirements.txt (pyttsx3). Aborts loudly if pip fails. On Ubuntu, install the eSpeak NG speech engine first.
Windows 11: src\01_venv_create.bat
Ubuntu 24.04: sudo apt install espeak-ng
Ubuntu 24.04: bash src/01_venv_create.sh
Step 2: activate the virtual environment
Activate the venv you just created. On Linux, source it so the environment variables apply to the current shell.
Windows 11: src\02_venv_activate.bat
Ubuntu 24.04: source src/02_venv_activate.sh
Step 3: run the text-to-speech demo
Speak the contents of data/input.txt line by line. Extra arguments are forwarded to the Python script.
Windows 11: src\03_text_to_speech.bat
Ubuntu 24.04: bash src/03_text_to_speech.sh
List the voices, speak a string, or save to a file:
bash src/03_text_to_speech.sh --list-voices
bash src/03_text_to_speech.sh --text "Hello world"
bash src/03_text_to_speech.sh --save-wav model/audio/output.wav
Step 4: clear the virtual environment (optional)
Delete the venv/ folder to free disk space when you no longer need it.
Windows 11: src\99_venv_clear.bat
Ubuntu 24.04: bash src/99_venv_clear.sh
[Python Entry Point]
- src/text_to_speech.py: [--input data/input.txt] [--text STRING] [--list-voices] [--voice ID] [--rate-delta -30] [--volume-delta -0.25] [--save-wav FILE].
- --input: the text file to speak, default data/input.txt, read line by line.
- --text: speak this string directly.
- --list-voices: print the installed voices and exit.
- --voice: select a voice by its id.
- --rate-delta / --volume-delta: how much to change the rate and the volume relative to the system defaults, -30 and -0.25 by default.
- --save-wav: write the speech to an audio file instead of playing it, for example model/audio/output.wav.
[Usage Notes]
- Everything runs locally: no internet and no GPU are needed.
- The installed voices differ from one operating system to the next, so check what you have with --list-voices.
- --save-wav writes a real wav on Windows and Linux; on macOS it writes AIFF-C data regardless of the file extension, which is a pyttsx3 quirk.
[References]
- pyttsx3: pypi.org/project/pyttsx3
This SDK is built in AppForAI - AI Dev Tools.
Purchase license separately: USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.