⬆️ ⬇️

Voice closing and opening the lid of the laptop and speech synthesis in Ubuntu

You can make the laptop talk when you open and close the lid, it will cheer you up and amuse your friends.



It will look like this: video on youtube .



And we will synthesize speech, that is, you write the text, and the laptop will say it. Naturally, this way you can customize what exactly your laptop will say when you close the lid.

')

Let's start:



nil To begin with, we will install a program that synthesizes speech, that is, converts the entered text into a voice. This program is called festival.



Note: In Ubuntu 8.04.1, espeak is already installed for speech synthesis, but its quality of pronunciation leaves much to be desired. To listen to how it synthesizes speech, type in the terminal:

espeak "hello"

If you are satisfied with this sound quality, you can not install the festival. In this case, simply replace the lines in the following script:

echo "closed" | festival --tts;

echo "opened" | festival --tts;


on their:

espeak "closed";

espeak "opened";




The festival program is in the official Ubuntu repository, to install it, execute the following commands in the terminal one by one:

sudo apt-get install festival

sudo apt-get install speech-tools




After the festival program is installed, you need to install voices with which it can speak. Let's install British English (male voice), for this we type in the terminal:

sudo apt-get install festvox-rablpc16k



So far, there is no Russian language in the official repository, so I was content with English, but if you are interested in the question of speech synthesis, you can install the Russian by downloading the archive from this site and unpacking it into the correct folder.



Now you can check if speech synthesis works, for this we type in the terminal:

echo "hello" | festival --tts

After that, you should hear a voice that says “hello”.



If there are any mistakes, then act on the circumstances to correct them. For example, I had the following Linux: can't open /dev/dsp problem Linux: can't open /dev/dsp , to fix this you need to type in the terminal (from the home directory):

printf ";use ALSA\n(Parameter.set 'Audio_Method 'Audio_Command)\n(Parameter.set 'Audio_Command \"aplay -q -c 1 -t raw -f s16 -r \$SR \$FILE\")\n" > .festivalrc

( The solution to the problem is taken from here )



Proceed to the next step only after you have synthesized speech.



1 . We open for editing the file /etc/acpi/lid.sh , for this we type in the terminal:

sudo gedit /etc/acpi/lid.sh



2 Add to this file after the line #!/bin/bash following text:

grep -q closed /proc/acpi/button/lid/LID/state

if [ $? = 0 ]

then

echo “ closed ” | festival –tts;

else

echo “ opened ” | festival –tts;

fi


Bold text will be pronounced. Naturally, you are free to enter any of your text there, for example, when closing: “What are you doing, idiot?” =).

Save and close the file.

Everything is ready, now the laptop will delight you with its angelic singing every time you open or close its lid.



A note for those who are at least a little versed in scripts: naturally, you are free to launch any program after closing / opening the lid, for example, the original article suggests playing wav files using the mplayer program.



The idea is taken from here .



PS: Post decided to publish to dilute the theme "Humor on Habrahabr", and then people are complaining that Habr has not been like itself lately. I myself am relatively recently registered, I hope I did it. Also a little bit of promotion of your blog , devoted mainly to the subject of Linux Ubuntu. Welcome !

Source: https://habr.com/ru/post/38012/



All Articles