Text to Speech [TTS] for Chat


Is it possible for bot to recognize 2 languages at the same time?
For example if command is written in russian !saу МЕМЫ it would use russian, but in case of !say MEMES it would use english voice?


I would be really grateful if someone can bring me or show me how to make this command only available for subs and also add a cooldown, since it’s a separate script doesn’t work out by putting it on the normal panel. Anyone can help? :slight_smile:


the command will be in the permissions area


Thanks mate! I now just need something in order to add a delay, really appreciated. :slight_smile:


!coolcom [command] [seconds] [type (global / user)]


!coolcom tts 60 user

will make a 1 minute cooldown per user.


Welp, yeah I got left behind when the forums moved. Thanks everyone who helped with this!
Updated things to hopefully work with PhantomBot 2.4.1, as it seems there was some restructuring done to PhantomBot’s alert handling at some point? This should work, it doesn’t give any errors, just have not been able to test it properly as audio hooks & alerts are silent for me at the moment (even on vanilla PhantomBot). If someone could test if for me, that’d be great.
speakSystem.js (1.9 KB) (Largely unchanged from Dakoda’s, just typo fixes in the comments iirc).
index.js (11.2 KB) Place in web/alerts/js/ and overwrite the existing file. Probably best to create a backup of the old file first.


Did a test and works with a browser, but not with obs browser plugin.


Excellent, thank you!
I believe the original script, for older versions of PhantomBot, only worked in a browser also. The QTWebkitBrowser plugin for OBS doesn’t seem to capture noise made by webpages. For Linux users, the “Linux Browser” plugin, however, does capture sound.


Outdated script. can anyone provide a updated one?



mine still works i just tested it so this isnt out of date :slight_smile:


Hi @peckingbird
Glad you joined us again in the forums. The tts script doesn’t work for me on my raspberry pi3 using Chrome and Streamlabs OBS with the browser source enabled. My audio hooks work though. I used to use !say [message] with the old version of Phantombot and it worked well. What is the command to initiate tts? Btw, I tried !tts !speak !say !shout none of these work for me.


have you tried my edit?


Sorry @Dakoda where is your edit? It works with the latest PB release?


Yes it works with the newest bot as i currently use it.

speakSystem.js (1.9 KB)

Then in BotFolder\web\alerts\js\alertHandler.js , add the following code above the line:
imageFileBasename = imageFile.substring(0, imageFile.indexOf('.'));

		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;


Thank you, though alertHandler.js was replaced by index.js, right? I can’t locate imageFileBasename = imageFile.substring(0, imageFile.indexOf('.'));


Ok so i have it all fixed…

in the index.js change

if (event.alert_image !== undefined) {
} else {


if (event.alert_image !== undefined) {
    if (event.alert_image.indexOf("<voice>") == 0) {
        var textToSpeak = event.alert_image.replace("<voice>" , "");//Remove "<voice>"
        //Pass text to window object.
        var speech = new SpeechSynthesisUtterance(textToSpeak);
        var voices = speechSynthesis.getVoices();
        var voiceSelect = 'Microsoft Zira Desktop - English (United States)';
        speech.voice = voices.filter(function(voice) { return voice.name == voiceSelect; })[0];
        speech.lang = 'en-US'; //Also added as for some reason android devices used for testing loaded spanish language 
        speech.volume = 0.50;
        speech.rate = 1.10;
        speech.pitch = 1.10;

        // Mark as done playing.
        isPlaying = false;
    } else {
} else {


This works perfectly for me. Thank you @Dakoda ! Is there a list of voices if I want to change the voice? For anyone else who is wondering, the alerts browser tab needs to be opened for the tts to be heard. I wondered if Streamlabs OBS would use the browser source to deliver the audio but it doesn’t work like that with tts.


Go to the link below and see what ones u have


I have quite a list. Not sure how to change to a particular voice though. I prefer en-US but nothing robotic. I like a natural sounding female voice.


I would start by changing Microsoft Eva - English (United States) to one of them names like say Samantha and see if that works