Introduction to gTTS
gTTS, which stands for Google Text-to-Speech, is a versatile Python library and command-line interface (CLI) tool designed to provide easy access to Google Translate's text-to-speech capabilities. By utilizing this tool, users can convert text into spoken MP3 audio files. These audio files can be written to a traditional file, a file-like object for further manipulation, or directly output to standard output (stdout).
Main Features
gTTS stands out with its customizable features that cater to a variety of speech generation needs:
-
Speech-specific Sentence Tokenizer: This feature allows users to input long text strings, which the tokenizer efficiently processes while maintaining correct intonations, recognizing abbreviations, handling decimals, and more.
-
Customizable Text Pre-processors: gTTS also offers pre-processors that can adjust the pronunciation of words to enhance clarity and accuracy in the generated speech.
Installation
Installing gTTS is straightforward and can be accomplished using Python's package installer, pip:
$ pip install gTTS
Quickstart Guide
gTTS can be accessed via the command line or as a module within a Python script:
Using the Command Line:
To convert text to speech and save it as an MP3 file, you can use the following command:
$ gtts-cli 'hello' --output hello.mp3
Using the Module:
For use within a Python script, gTTS provides a simple interface:
from gtts import gTTS
tts = gTTS('hello')
tts.save('hello.mp3')
For more comprehensive documentation and examples, users can visit the gTTS documentation.
Important Notes
It is important to highlight that the gTTS project does not have an official affiliation with Google or Google Cloud. The tool leverages the unofficial speech functionality from Google Translate, which may undergo changes without prior notice. It differs from the Google Cloud Text-to-Speech service.
Additional Information
For users seeking more information or wishing to participate in community discussions, there are several resources available:
License
The gTTS project is shared under the MIT License, granting freedom to use, modify, and distribute under the license terms. It is maintained by Pierre Nicolas Durette and contributors. Further details can be found in the [LICENSE] document.
By providing a reliable text-to-speech solution and engaging user community, gTTS offers a practical tool for developers and anyone interested in generating speech from text inputs.