ResponsiveVoice is a popular free Speech Text API tool that allows users to add reading text, words and snippets to their website. But how to customize these codes to perform the way you want?
ResponsiveVoice despite being free, has a paid plan that supports it. The big problem is that free users don't get attention. Neither API documentation will update what the service provides.
When trying to use and edit various codes, I couldn't get it to work the way I want. Fortunately with the help of AI, after several hours, I managed to edit the way I want with JavaScript.
How to add ResponsiveVoice to your website
To add ResponsiveVoice to your website, you need to create an account and generate an API key for your website. Then just put the following Script in the header of your project.
<script src="https://code.responsivevoice.org/responsivevoice.js?key=YOUR_UNIQUE_KEY"></script>
After adding this Script, you can create other javascript to make it work on your site. You can call the API to pronounce text of your choice, using strings, variables or predetermined texts.
It is possible to make the Script pronounce specific tags, selected text or even the whole page. For that, you just need to create the javascript and call the responsivevoice with the following code:
responsiveVoice.speak("text-or-var");
Adding parameters in responsiveVoice.Speak
To customize the ResponsiveVoice code, you can use the configuration options available in the ResponsiveVoice documentation. Some of the most common options include:
voice
: Lets you specify the voice that will be used to play the text (the language). You can choose from available voices for the selected language.
rate
: Allows you to control the speech rate. Higher values will result in faster speech, while lower values will result in slower speech.
pitch
: Allows you to control the speech pitch. Higher values will result in higher-pitched speech, while lower values will result in lower-pitched speech.
volume
: Allows you to control the speaking volume. Higher values will result in louder speech, while lower values will result in quieter speech.
To use these options, simply add them as parameters when calling the function responsiveVoice.speak()
.
Adding Button to pronounce an HTML element
In case you want to pronounce the content of a tag, you can do that with javascript below. In this case the Script adds a button on each
of the site, removes some HTML tags with regex (in my case