text to speach the date + time + temperature every hour when you are awake [raspberrypi]

based on:
http://blogs.uni-due.de/zim/2014/03/21/sprich-freund-und-tritt-ein-sprachausgabe-fur-den-raspberry-pi-mit-espeak-und-svox-pico/

I tested
flite:
sudo apt-get install flite -y
flite "Hello World."

festival:
sudo apt-get install festival -y
echo "Hello World." | festival --tts

espeak:
sudo apt-get install espeak -y
espeak -vde "Hallo Welt."
better with mbrola (mb-de4) but lags on my pi1 b:
espeak -v mb-de4 "Hallo Welt."

and pico.
I got best audio results with pico.

so i used pico to tell the date and time every hour when i am awake:

install pico:
try:
sudo apt-get install libttspico-utils -y
if the previous command does not work try this:
wget http://www.dr-bischoff.de/raspi/pico2wave.deb
sudo dpkg -i pico2wave.deb

Test pico:
pico2wave --lang=de-DE --wave=/tmp/test.wav "Hallo Welt." && aplay /tmp/test.wav && rm /tmp/test.wav

fit the locale:
sudo update-locale LC_TIME=de_DE.UTF-8
sudo reboot

make a script that speaks text:
nano /home/pi/pico_speak.sh

#!/bin/bash
pico2wave -l=de-DE -w=/tmp/test.wav "$1"
aplay /tmp/test.wav
rm /tmp/test.wav

make the script executeable:
chmod +x /home/pi/pico_speak.sh

test it with:
/home/pi/pico_speak.sh "Hallo Welt."

make a script that creates the text to speak:
nano /home/pi/create_date_text.sh

#!/bin/bash
declare -i day_of_month
day_of_month=$(date +"%e")
STRING=""
rm /home/pi/speaktest
echo "es ist" >>/home/pi/speaktest
(date +"%A") >>/home/pi/speaktest
echo "der" >>/home/pi/speaktest
if [ $day_of_month = 1 ];
	then
		STRING="erste"
elif [ $day_of_month = 3 ];
	then
		STRING="dritte"
elif [ $day_of_month = 7 ];
	then
		STRING="siebte"
else 
	STRING=$day_of_month"te"
fi
echo $STRING >>/home/pi/speaktest
(date +"%B") >>/home/pi/speaktest
echo " " >>/home/pi/speaktest
echo Uhrzeit: >>/home/pi/speaktest
(date +"%k") >>/home/pi/speaktest
echo Uhr >>/home/pi/speaktest
(date +"%M") >>/home/pi/speaktest
#echo " " >>/home/pi/speaktest
#echo Temperatur: >>/home/pi/speaktest
#page="$(curl http://homepage.de/wetter)"
#var2=$(echo "$page" | grep Temp: | sed 's/<hr>Temp:<br><b>//g' | sed 's/C<\/b><br>//g')
#var2=${var2::-2}
#var2=$var2" Grad"
#echo $var2 >>/home/pi/speaktest
#
###aktuelle temperatur###
echo " " >>/home/pi/speaktest
echo Aktuelle Temperatur: >>/home/pi/speaktest
page="$(curl http://openweathermap.org/city/2950159)"
var2=$(echo "$page" | grep "http://openweathermap.org/img/w/03n.png" | sed 's/<h2> <img src="http:\/\/openweathermap.org\/img\/w\/03n.png">//g' | sed 's/┬░C<\/h2>/ Grad/g')
echo $var2 >>/home/pi/speaktest
#
###Maximaltemperatur heute###
echo " " >>/home/pi/speaktest
echo Maximaltemperatur heute: >>/home/pi/speaktest
page="$(curl www1.wdr.de/themen/infokompakt/wetter/wetter_nrw_ea100_eam-cc69d231dca79ea2c2894ba948f21cc6.html?eap=8oI34N4hym4RDV6dhKK0OnLYM%2FNzIoiKEQqHYZPZjFxpkU74v6xP%2Bd7htYRzReo%2BbDdl5sZUTmCuC2OmskTACpK2C4%2FEK5EjugWLsGnWIGP7RItF29dM89qkzrHLru%2BoeIPsPAW%2FDve0eoTm3UNURoCnphI%2By8U6)"
var3=$(echo "$page" | sed '/<td class="forecast-1" headers="max-temp forecast-1">/,$d' | sed -n '/<td class="forecast-0" headers="max-temp forecast-0">/,$p' | sed 's/<\/td><td class="forecast-0" headers="max-temp forecast-0">//g' | sed 's/<abbr title="Grad Celsius"> &deg\;C<\/abbr>/ Grad/g')
echo $var3 >>/home/pi/speaktest
#
###Maximaltemperatur morgen###
echo " " >>/home/pi/speaktest
echo morgen: >>/home/pi/speaktest
var4=$(echo "$page" | sed '/<td class="forecast-2" headers="max-temp forecast-2">/,$d' | sed -n '/<td class="forecast-1" headers="max-temp forecast-1">/,$p' | sed 's/<\/td><td class="forecast-1" headers="max-temp forecast-1">//g' | sed 's/<abbr title="Grad Celsius"> &deg\;C<\/abbr>/ Grad/g')
echo $var4 >>/home/pi/speaktest
#
###Maximaltemperatur uebermorgen###
echo " " >>/home/pi/speaktest
echo ├╝bermorgen: >>/home/pi/speaktest
var5=$(echo "$page" | sed '/<td class="forecast-3" headers="max-temp forecast-3">/,$d' | sed -n '/<td class="forecast-2" headers="max-temp forecast-2">/,$p' | sed 's/<\/td><td class="forecast-2" headers="max-temp forecast-2">//g' | sed 's/<abbr title="Grad Celsius"> &deg\;C<\/abbr>/ Grad/g')
echo $var5 >>/home/pi/speaktest

exit with ctrl+x -> confirm with “y” -> accept with “enter”

make the script executeable:
chmod +x /home/pi/create_date_text.sh

test it with:
/home/pi/create_date_text.sh && /home/pi/pico_speak.sh "$(cat /home/pi/speaktest)"

create a script that checks for quiet hours (so it does not talk when you sleep):
nano /home/pi/keep_peace_at_night.sh

#!/bin/bash
if [ $(date +"%k") -lt 23 ]
then
        if [ $(date +"%k") -gt 5 ]
        then
        /home/pi/create_date_text.sh && /home/pi/pico_speak.sh "$(cat /home/pi/speaktest)"
        fi
fi
# this script will not work from 22:00 -6:00

exit with ctrl+x -> confirm with “y” -> accept with “enter”

make the script executeable:
chmod +x /home/pi/keep_peace_at_night.sh

add the script to the crontab:
crontab -e
and paste the following line at the end:
0 */1 * * * /home/pi/keep_peace_at_night.sh

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s