With gTTS, we'll show you how to convert text to speech from the command prompt using the Google Translate API. This command-line tool lets you take short or long texts and save them as MP3 audio files. But the most important feature is the ability to customize the conversion or set language rules.
There are many “Text to Speech” programs, but the advantage of “gTTS” is its use of the Google Translate API, which is more accurate, reliable, and supports almost all languages, including Spanish.
Convert text to speech from the CMD window using the Google Translate API
First you will have to install the tool through Python, so you can later use the gTTS library from a Command Prompt window.
After installing gTTS from Python, you will have to check that the PIP library for gTTS works correctly. To do this, run the following code in the CMD window:
pip install gTTS
Now you have everything ready to enter the syntax to convert text to speech using the Google Translate API. The .mp3 files will be saved in the output folder (you can modify it).
gtts-cli "InputText" –output audio.mp3
That command generates an audio file at normal speed. But if you want to go a little further, the platform has modules to customize the speech, such as generating “Tokenizer”, changing the voice, reducing the speed of the narration, applying specific rules to a language, creating strings (tokens), etc. These enhancers will expand the gTTS tools. If you need more technical details about the environment, click here.
The level of conversion to Spanish is really very good. gTTS is a simple platform to convert text to speech in a simple and effective way. You can also use the utility in your own developments. gTTS is an open source program.