Making Yourself A Free Text To Speech Program In Linux in 5 Minutes!

Making Yourself A Free Text To Speech Program In Linux in 5 Minutes!

Here is a small project on how to make a simple bash script to make your computer speak what you have highlighted in a web browser, consider it as a personal assistant to read the text out.

You can use it while doing some other things, don’t expect it to be so perfect with the punctuation as it is not based on the artificial intelligence or has a huge database to predict the perfect pronunciation for words.


So, let’s cut the talking and get on to the code.

First, you need to make sure you have all the packages available on your Linux machine.

(I love open source software and in this tutorial, we are gonna pipe down to Open source software to make our computer speak for us.)


So there are two packages you need to install for this.

well, just copy the code below.
(I am using a Debian based Linux.)


#apt-get install festival

Festival is the first package to be installed and in case you want to check whether it works on your computer or not just run these commands in your terminal.


# echo "welcome to Hackingvision, have you subscribed to our notifications?" > test
# festival --tts test

Now the second package is what helps to take the highlighted text as an input for that we have an amazing open-source tool called xsel you can install it by typing the following command.


#apt-get install xsel


now we need to write our small bash script to make these two tools work together basically we are taking the input from xsel and treating that as an input to the festival tool which will convert that text to speech.

here is the bash script

xsel | festival --tts --pipe


copy the above code and save the above script with a .sh extension in the home directory.

As I told just a single line and why we needed it as a script is because the next step we are gonna make this script run when we highlight a sentence and give a custom keyboard shortcut to the script.

The next step is to add a shortcut key combination to run the script whenever we want. To do that go to settings > keyboard > scroll down and click on add.




now give it a name you want to and in command just type “./” give a shortcut you want and apply.




Now just go to the web and test it out and if it worked for you leave us a comment here. and share the article subscribe to our Newsletters to stay updated.