English English

Text-to-speak software for Linux - console program that can also be automated

gTTS (Google Text-to-Speech), a Python program and console program that uses speech output from the Google Translate API. The program converts text to an mp3 file (default), a data object byte string, or stdout. It can also use a text pre-processing program to correct the text for errors before speech output.

Installation

gTTS needs previously installed Python environment. The program works on Python 2.7 and Python 3.x.

It can be installed via the package manager pip (recommended). The package manager must be installed before.

pip install gTTS

 

Usage

The program can only be called from the console. It is also possible to automate the creation of speech output via shell scripts. Here are two examples how to call the program from the shell console. Also an example on how to use the program in a Python script.

Example: Outputting Text Directly in English

gtts-cli 'Hello. It is now 3 pm. We will close now. Thank you for visit.' --lang en --output information.mp3

Example: Outputting a Text File in English

gtts-cli -f /home/ubuntu/weather_forecast.txt -l 'en' -o audio.mp3

Call as Python module via a Python script

Output of the text "Hello" in English.

from gtts import gTTS
tts = gTTS('hello', lang='en')
tts.save('hello.mp3')

 

Program commands

All commands of gTTS to use further functionalities of this program.

The program must be called in this order:

gtts-cli [OPTIONS] <text>

The text must be added as string or as path to the text file in <text>.

 

All OPTIONS commands:

-f, --file <file>

Read from <file> instead of <text>.

-o, --output <output>

 Write to <file> instead of stdout.

-s, --slow

Read slower.

-l, --lang <lang>

IETF Language identifier. Language in which you can speak. All available languages can be output with this command: -all. Default: en]

--nocheck

Disable strict IETF language tag checking. Allow undocumented tags.

--all

Print all documented available IETF language tags and exit.

--debug

Show debug information.

--version

Show the version and exit.

 

All available languages and further information

The following languages are available as voice output:

German, English, French, Dutch, Spanish, Portuguese, Italian, Chinese Mandarin, Japanese, Korean, Turkish, and more.

All languages can be output with this command:

gtts-cli --all

 

Further documentation on gTTS (official website) is available on this website:

https://gtts.readthedocs.io/en/latest/index.html

 

We use cookies on our website. They are essential for the operation of the site
Ok