Text to Speech [TTS] for Chat

You can use this updated script, which will read the sender’s name:

speakSystem.js (1.1 KB)


Thank you a lot!

sorry for more tiny request but u could provide the template for Brazilian language?

@mausmani Thank you so much for the thorough documentation. I tested this speaksystem in Chrome and it works well. When I try it using Microsoft Edge, it doesn’t speak. Now, the script that I initially posted in this thread does work with Microsoft Edge. Do you know what is the difference that makes the script by @peckingbird work in Edge and the one you wrote not work? To be clear, I love your script as it addresses many issues I had with the old script. I am trying to understand why it will not speak using Microsoft Edge. I feel that browser uses less memory and therefore is better when I stream. Thank you!

You will need to get the compatible voices for Edge browser. I just modified these 2 lines in alertHandler.js to the compatible voice in Edge browser:

speech.voice = voices.filter(function(voice) { return voice.name == 'Microsoft David Mobile - English (United States)'; })[0];
speech.lang = 'en-US';

This should work.

1 Like


As per the website I had linked:

speech.voice = voices.filter(function(voice) { return voice.name == 'Google português do Brasil'; })[0];
speech.lang = 'pt-BR';
1 Like

Awesome! Thank you. It works great. I actually like Zira’s voice better so I changed it to:

speech.voice = voices.filter(function(voice) { return voice.name == 'Microsoft Zira Mobile - English (United States)'; })[0];
speech.lang = 'en-US';

I love it!

1 Like

Glad it worked for you!

1 Like

Updated the script with the cost for the command and a command to set the cost :slight_smile: i also renamed the command to tts instead of say

speakSystem.js (1.9 KB)

1 Like

Will one of you legends be working to get this functioning with 2.3.9 as currently, I can’t seem to get it to work :frowning: I’d offer to help, but I’m not sufficiently knowledgable sadly.

working fine for me as it is :slight_smile:

1 Like

I upgraded tonight and my tts still works fine. I made sure to follow the instructions above and cross-referenced my previous alertHandler.js file where I had modified it as instructed here. You do also open the alert window in your browser, right?

Just an update to allow the rate of the speed the voice!

if (imageFile.substring(0,7) == "<voice>"){//Check if voice alert.
    var textToSpeak = imageFile.substring(7);//Remove "<voice>"
    //Pass text to window object.
    var speech = new SpeechSynthesisUtterance(textToSpeak);
    var voices = window.speechSynthesis.getVoices();
    speech.default = false;
    speech.voice = voices.filter(function(voice) { return voice.name == 'Google UK English Male'; })[0];
    speech.lang = 'en-GB'; //Also added as for some reason android devices used for testing loaded spanish language 
    speech.volume = 0.70;
    speech.rate = 0.70;
1 Like

I think the latest Windows 10 update broke tts when using Microsoft Edge. Is there an update to the code that would enable tts again? I like using Edge because it seems to not take up many resources while streaming and gaming.

i just looked into it and im kind of lost cus the function below works with javascript just fine which is almost the same as what we already have

function speak(textToSpeech) {
    var synUtterance = new SpeechSynthesisUtterance(textToSpeech);
    synUtterance.voice = voices.filter(function(voice) { return voice.name == 'Google UK English Male'; })[0];
    synUtterance.lang = langSelect.value;
    synUtterance.volume = parseFloat(volumeRange.value);
    synUtterance.rate = parseFloat(rateRange.value);
    synUtterance.pitch = parseFloat(pitchRange.value);


this link is where i did a test on edge and there way worked fine

Yeah, that is weird. I went to the link using Edge and it says it is supported and does speak text within that page. When I launch the PB control panel and open alerts and use my !say command, nothing happens. So the code is the same as what speech synthesis api is and it doesn’t work?

did you ever get this to work yet?

Thanks for asking. No, unfortunately not with the Edge browser. It works as expected using Chrome, so I’m sticking with that until a solution comes around. I’m not sure what Microsoft changed to cause the script to not work in Edge.

ill have a look when i redo the code for the tts over then next few weeks

1 Like

That’d be great! Thanks