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.
$ apt-get install speex
$ apt-get install libspeex-dev
$ apt-get install qjackctl
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:
./iip.sh | 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 xip.py application from GitHub:
In order to make your Kali Linux speak your External IP address (WAN) use the following command:
python xip.py | 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 speech.sh:
#!/bin/bash
TEXT=$*
mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$TEXT"
Don't forget to make it executable: $ chmod 764 speech.sh
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:
./speech.sh You have reached such and such. At the moment it is not possible to take this call. && ./speech.sh Please, try again later or leave a message after the tone.
As you can see, in the previous command I used the speech.sh 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: http://elinux.org/RPi_Text_to_Speech_%28Speech_Synthesis%29
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:
Now, run the command:
Note that the speech_google.sh is similar to the speech.sh script described in the previous example. However, speech_google.sh 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:
https://defuse.ca/blog/raspberry-pi-enable-mplayer-and-vlc-audio-on-rasbian.html
https://jeffskinnerbox.wordpress.com/2012/11/15/getting-audio-out-working-on-the-raspberry-pi/
>> Using espeak:
First of all you need a script that will output your LAN IP address. You can use my iip.sh script from GitHub:
$ git clone https://github.com/drgfragkos/iip.git
Don't forget to make it executable: $ chmod 764 iip.sh
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_bcm2835make 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
./iip.sh | 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 xip.py application from GitHub:
$ git clone https://github.com/drgfragkos/xip.git
In order to make your Kali Linux speak your External IP address (WAN) use the following command:
python xip.py | 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 speech.sh:
#!/bin/bash
TEXT=$*
mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$TEXT"
Don't forget to make it executable: $ chmod 764 speech.sh
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:
./speech.sh You have reached such and such. At the moment it is not possible to take this call. && ./speech.sh Please, try again later or leave a message after the tone.
As you can see, in the previous command I used the speech.sh 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: http://elinux.org/RPi_Text_to_Speech_%28Speech_Synthesis%29
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 https://github.com/drgfragkos/time2speech.git
Now, run the command:
$ ruby time2words.rb | ./speech_google.sh >/dev/null 2>&1
Note that the speech_google.sh is similar to the speech.sh script described in the previous example. However, speech_google.sh 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:
https://defuse.ca/blog/raspberry-pi-enable-mplayer-and-vlc-audio-on-rasbian.html
https://jeffskinnerbox.wordpress.com/2012/11/15/getting-audio-out-working-on-the-raspberry-pi/
No comments:
Post a Comment