Install Gtts For Python In Mac

GTTS-token (Google Text to Speech token): A python implementation of the token validation of Google Translate. Install pip install gTTS-token Description. Google Translate requires a tk param when making a request to its translate API. This project provides an implementation for that algorithm in Python. Text to Speech (TTS) library for Python 2 and 3. Works without internet connection or delay. Supports multiple TTS engines, including Sapi5, nsss, and espeak. Before you jump into the guide, do take note that there are multiple ways to install Python 3 on a Mac but with this guide, I’ll show you the two easiest ways to do this, step-by-step. Personally, the way I did it was using a package manager like HomeBrew (it’s okay if you don’t understand what it is).

Text-to-Speech (TTS) is a kind of speech synthesis which converts typed text into audible human-like voice.

There are several speech synthesizers that can be used with Python. In this tutorial, we take a look at three of them: pyttsx, Google Text-to-Speech (gTTS) and Amazon Polly.

We first install pip, the package installer for Python.

If you have already installed it, upgrade it.

Install

We will start with the tutorial on pyttsx, a Text-to-Speech (TTS) conversion library compatible with both Python 2 and 3. The best thing about pyttsx is that it works offline without any kind of delay. Install it via pip.

By default, the pyttsx3 library loads the best driver available in an operating system: nsss on Mac, sapi5 on Windows and espeak on Linux and any other platform.

Import the installed pyttsx3 into your program. Suzuki ltr 450 repair manual free download.

Here is the basic program which shows how to use it.

Now let us change the voice in pyttsx3 from male to female. If you wish for a female voice, pick voices[10], voices[17] from the voices property of the engine. Of course, I have picked the accents which are easier for me to make out.

You can actually loop through all the available voices and pick the index of the voice you desire.

Python

Now, Google also has developed an application to read text on screen for its Android operating system. It was first released on November 6, 2013.

Gtts

It has a library and CLI tool in Python called gTTS to interface with the Google Translate text-to-speech API.

We first install gTTS via pip.

gTTS creates an mp3 file from spoken text via the Google Text-to-Speech API.

We will install mpg321 to play these created mp3 files from the command-line.

Using the gtts-cli, we read the text 'Hello, World!' and output it as an mp3 file.

We now start the Python interactive shell known as the Python Shell

You will see the prompt consisting of three greater-than signs (>>>), which is known as the Python REPL prompt.

Import the os module and play the created hello.mp3 file.

Putting it all together in a single .py file

The created hello.mp3 file is saved in the very location where your Python program is.

gTTS supports quite a number of languages. You will find the list here.

The below line creates an mp3 file which reads the text '你好' in Chinese. Microsoft visio professional free. download full version.

The below program creates an mp3 file out of text '안녕하세요' in Korean and plays it.

Amazon also has a cloud-based text-to-speech service called Amazon Polly.

If you have an AWS account, you can access and try out the Amazon Polly console here:

The interface looks as follows.

There is a Language and Region dropdown to choose the desired language from and several male and female voices to pick too. Pressing the Listen to speech button reads out the text typed into the text box. Also, the speech is available to download in several formats like MP3, OGG, PCM and Speech Marks.

Now to use Polly in a Python program, we need an SDK. The AWS SDK for Python is known as Boto.

We first install it.

Gtts

Now to initiate a boto session, we are going to need two more additional ingredients: Access Key ID and the Secret Access Key.

Login to your AWS account and expand the dropdown menu next to your user name, located on the top right of the page. Next select My Security Credentials from the menu.

A pop-up appears. Click on the Continue to Security Credentials button on the left.

Expand the Access keys tab and click on the Create New Access Key button.

As soon as you click on the Create New Access Key button, it auto creates the two access keys: Access Key ID, a 20-digit hex number, and Secret Access Key, another 40-digit hex number.

Now we have the two keys, here is the basic Python code which reads a given block of text, convert it into mp3 and play it with mpg321.

Install Gtts For Python In Mac 2

There is also another way to configure Access Key ID and the Secret Access Key. You can install awscli, the universal command-line environment for AWS,

and configure them by typing the following command.

Gtts Python Install

Notes

Install Gtts For Python In Mac 10

  • The latest documentation on pyttsx3 is available here.
  • You can also access the updated documentation on gTTS here.