A simple demo that uses the Google Cloud Text-To-Speech API in JavaScript. Try it out! (Tested in Firefox)
- Create your personal Google Could API key. Make sure billing is enabled on your account (there should be a 12-month trial with some free credits if you sign up for the first time).
- Optional: Add your API key to
js/api-key.js
to have it automatically filled in the input field. WARNING - Do not commit your API key in git! Make sure you tell git to ignore changes to this file:git update-index --skip-worktree js/api-key.js
- Clone this repo, open the
index.html
in a browser. - Enter the API key in the web page and press the "Submit" button.
- Select the preferred language, gender and voice (WaveNet voices typically sound better than Standard voices).
- Enter some text and press the "Speak" button.
- You should now hear the spoken audio.
We use the REST API.
There are two asynchronous functions in scripts/main.js
that actually make the REST calls:
retrieveAvailableVoices()
-> This requests the available voicesretrieveSpeechAudio(textToSpeak)
-> This requests the synthesised audio for the given text and selected voice. Audio is returned as MP3 encoded as base64. There are also options for setting the pitch and speed. The API also supports SSML instead of basic text.
You are free to use code from this demo in your project according to the MIT license.