Monday, 25 May 2015

Personal Greeting for your mobile phone, using a bash script, Kali Linux and the Raspberry Pi

First of all, this is a quick way for making your Kali Linux speak. I am going to tell about a couple of ways to do text-to-speech on your Linux box. I used this for fun, for having audio alerts embedded to my applications and finally for recording a personal greeting for my phone. 
I started playing with espeak, and experimented with the different voices. The espeak application is fantastic but the different voices/languages it has, are too computerised. They do not sound as natural as you would have expected. However, for some quick tasks like listening to your LAN and/or WAN IP address, it can be useful, and cool.

>> Using espeak:
First of all  you need a script that will output your LAN IP address. You can use my script from GitHub: 
$ git clone

Don't forget to make it executable: $ chmod 764

Now make sure you have everything you need for making espeak to work.
I suggest running the following commands* to make sure everything is up-to-date:

$ apt-get update
$ apt-get upgrade
$ apt-get install espeak
$ apt-get install speex
$ apt-get install libspeex-dev
$ apt-get install qjackctl
$ apt-get install alsa-utils
$ modprobe snd_bcm2835

make sure your speakers are connected to the Raspberry Pi and they are loud enough. Use the command alsamixer to turn up the volume output of your Raspberry Pi. Test if you can hear a sound from your speakers using aplay and a .wav file:
$ aplay /usr/share/sounds/alsa/Front_Center.wav

In order to make your Kali Linux speak your Internal IP address (LAN) use the following command:
./ | sed -e 's:\.: dot :g' | sed -e 's: 0 : zero :g' | espeak -v en+f5 -s 160 2>>/dev/null

If you want to hear your External IP address, you will need to download my application from GitHub: 
$ git clone

In order to make your Kali Linux speak your External IP address (WAN) use the following command:
python | sed -e 's:\.: dot :g' | sed -e 's: 0 : zero :g' | espeak -v en+f5 -s 160 2>>/dev/null

>> Using Google:
Well, you must be online in order to use this method. However, it is convenient and the end result sounds as natural as possible. Create a new bash script with the following code and save it as

mplayer -user-agent Mozilla "$TEXT"

Don't forget to make it executable: $ chmod 764

Note that Google wont accept text more than 100 characters long at each request. So, make sure your sentences are smaller than that, or make more than one requests in one line of code:

./ You have reached such and such. At the moment it is not possible to take this call. && ./ Please, try again later or leave a message after the tone. 

As you can see, in the previous command I used the script twice with && in between. That way, the necessary pause will take place after the period and it will sound natural. You can now record this message as your personal greeting for your mobile phone. Having the nice lady greeting your callers with a personalised message feels like you have your own secretary! :) Trust me, the above scripts work really well and if you follow the instructions you will end up with an amazing greeting in no time. The reason why I am using these scripts is because, I can now use them for adding sound alerts to my applications!!!

You can find some more info about text to speech methods at:

Bonus Round:
For those of you who managed to read the whole post I have a small bonus round. I will saw you how to convert the current time to speech. First of all you need a way to convert the current time from digits to actual words, as it tends to sound a lot better when it goes through the text-to-speech process.

Download my time2speech project from GitHub:
$ git clone

Now, run the command:
$ ruby time2words.rb | ./ >/dev/null 2>&1

Note that the is similar to the script described in the previous example. However, is a script that you can pipe text to it from any tool you like. 

*If you reboot your raspberry pi and the sound stops working, then you need to add the module name (snd_bcm2835) as a new line in /etc/modules file. 

a couple of useful links for further reading:

No comments:

Post a Comment