Amazon Polly (TTS)— Head start tutorial

Oscar Leal
3 min readNov 17, 2019

--

Last week I stumbled upon this amazing Amazon Web Service called Polly. It is a speech synthesis TTS (Text-to-Speech) web service.

There is a library in order to be able to use this service directly with R. It is located here.

As a first step, you must be already counting with an Amazon Web Services account, if you haven’t done so, it won’t take more than a couple minutes, for more information follow this link.

For a preference I count with the editor RStudio Version 1.2.1335 installed in my machine, but you can use the editor of your preference that supports R.

Now, in order to be able to configure the information that the R script needs to connect with AWS.Polly, we’ll make use of the Amazon Command Line Interface. This can be found here: http://docs.aws.amazon.com/cli/latest/userguide/installing.html

Afterwards, direct yourself to the command line and type “$aws configure” and follow the rules, and to finalize, we will get the session token using the command “$aws sts get-session-token — duration-seconds 129600” (enter your own duration).

With the information it will throw out the last command, you go ahead and paste in the R script. Like this:

Afterwards, we install the library of aws.polly like this:

We then include the library with library(“aws.polly”), and now we can see a list of possible voices that you can use with the function “list_voices()”. Here is an example of the voices available.

We will need the name of the desired voice to be used by the service, and plug it with the text that will be converted.

The result of this call, will be a “Wave” object from the tuneR package, which should also be included in the script, afterwards, we can reproduce the audio by just using it with play():

This previous command executes the .wav file automatically and you can instantly hear it. You can also install the library “seewave” and you could save the wav into your disk, and make use of it as you wish.

The result file for this exercise can be found here.
Hope it will be use for some of you.

All the best,
Oscar Leal

--

--

Oscar Leal
Oscar Leal

Written by Oscar Leal

Software Engineer, and Data Analyst. Currently studying in Central European University — Budapest campus

No responses yet