Search code examples
javascripthtmlapitext-to-speechresponsivevoice

responsivevoice - I have to read the text inside the html element to the sound robot


responsivevoice .org I couldn't do the text voice over service as I wanted. There is no detailed explanation on the website.

I don't want to use < textarea > The example I want to use. I don't want to choose a robot. It should only speak Turkish Male. How should I do this?

<div id = "text-read"> one two tree four five </div>

<button onclick="responsiveVoice.speak('text-read');" type="button" value="Play">Play</button>

I want it to read the contents with the button. Thank you for your interest

resources:
https://responsivevoice.org/api
https://responsivevoice.org/text-to-speech-sdk/text-to-speech-play-button
https://responsivevoice.org/text-to-speech-sdk/text-to-speech-widget


Solution

  • The first parameter of the speak function represents the text to be spoken, the second one defines the voice:

    responsiveVoice.speak('bir, i̇ki, üç', 'Turkish Male');
    

    If you want to get the text that is inside some HTML element, you have to query it first, then get its text content and finally pass that to the function:

    var element = document.getElementById('text-read');
    var text = element.innerText;
    responsiveVoice.speak(text, 'Turkish Male');