Command-line (gtts-cli)

After installing the package, the gtts-cli tool becomes available:

$ gtts-cli

gtts-cli

Read <text> to mp3 format using Google Translate’s Text-to-Speech API (set <text> or –file <file> to - for standard input)

gtts-cli [OPTIONS] <text>

Options

-f, --file <file>

Read from <file> instead of <text>.

-o, --output <output>

Write to <file> instead of stdout.

-s, --slow

Read more slowly.

-l, --lang <lang>

IETF language tag. Language to speak in. List documented tags with –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.

Arguments

<text>

Optional argument

Examples

List available languages:

$ gtts-cli --all

Read ‘hello’ to hello.mp3:

$ gtts-cli 'hello' --output hello.mp3

Read ‘bonjour’ in French to bonjour.mp3:

$ gtts-cli 'bonjour' --lang fr --output bonjour.mp3

Note

Alternatively, you can enclose your text with quotation marks to avoid errors associated with phrases that may need the use of an apostrophe:

$ gtts-cli "c'est la vie" --lang fr --output test.mp3

Read ‘slow’ slowly to slow.mp3:

$ gtts-cli 'slow' --slow --output slow.mp3

Read ‘hello’ to stdout:

$ gtts-cli 'hello'

Read stdin to hello.mp3 via <text> or <file>:

$ echo -n 'hello' | gtts-cli - --output hello.mp3
$ echo -n 'hello' | gtts-cli --file - --output hello.mp3

Read ‘no check’ to nocheck.mp3 without language checking:

$ gtts-cli 'no check' --lang zh --nocheck --ouput nocheck.mp3

Note

Using --nocheck can make the command slightly faster. It exists however to force a <lang> language tag that might not be documented but would work with the API, such as for specific regional sub-tags of documented tags (examples for ‘en’: ‘en-gb’, ‘en-au’, etc.).

Playing sound directly

You can pipe the output of gtts-cli into any media player that supports stdin. For example, using the play command from SoX:

$ gtts-cli 'hello' | play -t mp3 -