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: permite especificar a voz que será usada para reproduzir o texto (o idioma). Você pode escolher entre as vozes disponíveis para o idioma selecionado.
rate: permite controlar a velocidade da fala. Valores mais altos resultarão em fala mais rápida, enquanto valores mais baixos resultarão em fala mais lenta.
pitch: permite controlar o tom da fala. Valores mais altos resultarão em fala mais aguda, enquanto valores mais baixos resultarão em fala mais grave.
volume: permite controlar o volume da fala. Valores mais altos resultarão em fala mais alta, enquanto valores mais baixos resultarão em fala mais baixa.
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