Text to speech using JavaScript and Python and AWS Polly

Yogitha O
3 min readJun 9, 2017

Giving voice responses is an important feature of your application these days. In this post, we will discuss how to convert text to speech using JavaScript and Python.

Among all the ways using simple JavaScript library is an easy process to convert a text into speech. All we need to do is add the JavaScript library and call the respective function with text you want to convert to speech as an argument.

I am using ResponsiveVoice.JS plugin for this. Please follow the following procedure and sample code snippets provided.

Download the plugin from the website and add it to your HTML page or use the CDN in your HTML page as shown below.

For different usages please follow the code snippets.

Fetching all Available voices

Stopping, pausing and resuming the voice

Conversion when the browser supports voice

I will show you two ways for Text to speech conversion using python.

polly is a text to speech synthesis service from AWS. It is a very simple service to use. All you need is AWS subscription.

we can test AWS services using in multiple ways like AWS CLI(command line interface),API Client for different technologies and using AWS console.

  • To test polly in AWS console login to your AWS account and go to polly console. Fill the text area and choose the language and region and voice and click on listen to speech button.

By using polly API client we can do all operations which can be performed on AWS console such upload your own lexicon and can use it for text to speech synthesis besides using the default voices provided by the Polly etc.

Install boto3 client by using these instructions.

  • Once your installation is successfully completed then we need to create a Client Object for polly as shown below.

once you create a client you can do all the operations that you can do on AWS polly console like getting the supported voices, synthesising speech,uploading a lexicon,deleting a lexicon etc…

To know all the voice in the particular language

To convert text to speech

to convert the text into speech the request will look like

install it using below command in linux

sudo pip install pyttsx

converting text to speech using pyttsx

Besides just conversion you can also add events.

For more information on using pyttsx please visit here.

That’s it. Happy conversion!

--

--