Last active
April 27, 2017 03:26
-
-
Save NonaSuomy/8a41816defe7b3d918c147d9d274c101 to your computer and use it in GitHub Desktop.
ESP-Radio with Text To Speech for OpenHab https://github.com/Edzelf/Esp-radio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/opt/openhab/conf/items/demo.items <= remove this line before use... | |
Number Switch2 "Door State [MAP(switchs.map):%s]" <garagedoor> (gG) {mqtt="<[broker:hq/garage/switch1:state:default]"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/opt/openhab/conf/rules/demo.rules <= remove this line before use... | |
rule "TTS GDS Action" | |
when | |
Item Switch2 changed | |
then | |
var doorState = Switch2.state | |
var doorStateLast = 5 | |
if ( doorState != doorStateLast ){ | |
doorStateLast = doorState | |
if (Switch2.state.toString.matches("0"){ | |
executeCommandLine("/opt/openhab/conf/scripts/webradioclitts.sh Hello-Family-Your-garage-door-is-closed.") | |
} | |
if (Switch2.state.toString.matches("1"){ | |
executeCommandLine("/opt/openhab/conf/scripts/webradioclitts.sh Hello-Family-Your-garage-door-is-open.") | |
} | |
if (Switch2.state.toString.matches("2"){ | |
executeCommandLine("/opt/openhab/conf/scripts/webradioclitts.sh Hello-Family-Your-garage-door-is-closing.") | |
} | |
if (Switch2.state.toString.matches("3"){ | |
executeCommandLine("/opt/openhab/conf/scripts/webradioclitts.sh Hello-Family-Your-garage-door-is-opening.") | |
} | |
if (Switch2.state.toString.matches("4"){ | |
executeCommandLine("/opt/openhab/conf/scripts/webradioclitts.sh Hello-Family-Your-garage-door-is-ajar.") | |
} | |
} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/opt/openhab/conf/sitemaps/demo.sitemap <= remove this line before use... | |
sitemap demo label="Main Menu" | |
{ | |
Frame { | |
Group item=gFF label="First Floor" icon="firstfloor" | |
Group item=gGF label="Ground Floor" icon="groundfloor" | |
Group item=gC label="Cellar" icon="cellar" | |
Group item=Garden icon="garden" | |
Group item=HCSR icon="temperature" | |
Text item=gG label="Garage" icon="garage" { | |
Text item=Weather_Temps | |
Text item=Weather_Humis | |
Text item=Weather_Baros | |
Text item=Switch2 | |
Switch item=GarageDoorRelay1 | |
Text item=Switch1 | |
Switch item=Relay1 mappings=[ON="Go!"] | |
Text item=Available | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/opt/openhab/conf/transform/switchs.map <= remove this line before use... | |
0=Closed | |
1=Open | |
2=Closing | |
3=Opening | |
4=Ajar | |
UNDEFINED=Unknown | |
-=Unknown |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script: webradioclitts.sh | |
# Contact: nonasuomy.github.io | |
# Description: ESP-Radio + online google tts + offline pico2wave | |
# Date: 20170426 | |
# Dependancies: cURL (_POST url to ESP-Radio) https://www.archlinux.org/packages/community/x86_64/curl/ | |
# svox-pico-bin [pico2wave] (popt sox (sox-dsd-git)) https://aur.archlinux.org/packages/svox-pico-bin/ | |
# (Optional alternative tts engine) espeak (libpulse portaudio) https://www.archlinux.org/packages/community/x86_64/esp$ | |
# [mpg123] (alsa-lib libltdl (libtool) libpulse https://www.archlinux.org/packages/extra/x86_64/mpg123/ | |
# vorbis-tools [ogg123] (curl flac libao libvorbis) https://www.archlinux.org/packages/extra/x86_64/vorbis-tools/ | |
# sox [play] (file gsm lame libltdl (libtool) libpng libsndfile opencore-amr wavpack) | |
# (Optional if you don't want to use sox:play above.) alsa-utils [aplay] | |
# iputils [ping] (libcap openssl sysfsutils) https://www.archlinux.org/packages/core/x86_64/iputils/ | |
#/opt/openhab/conf/scripts/webradioclitts.sh | |
#/opt/openhab/conf/html/glass.mp3 or barking.mp3 etc for notification. | |
#*Note: I converted the glass.ogg to an mp3 for the sake of the webradio streaming better. | |
#Testing sudo ./webradioclitts.sh hello-there-how-are-you (dashes required by web tts api) | |
# Settings: | |
webradio="10.13.37.65" | |
openhab="10.13.37.42:8080" | |
# Checks to see if we have a WAN connection. | |
online=false | |
if [[ $(ping -q -c1 8.8.8.8 > /dev/null 2>&1; echo $?) -eq 0 ]]; then | |
online=true | |
else | |
online=false | |
fi | |
# Play a pre-notification sound (Some systems don't have the default sound files.) | |
# WebRadio send notification sound. | |
onlinewebradio=false | |
if [[ $(ping -q -c1 $webradio > /dev/null 2>&1; echo $?) -eq 0 ]]; then | |
# Add one of the sound files below to openhab's static web folder /opt/openhab/conf/html/glass.mp3 etc. | |
/usr/bin/curl --data "station="$openhab"/static/barking.mp3" $webradio > /dev/null 2>&1 | |
onlinewebradio=true | |
else | |
# Sound files: https://cgit.freedesktop.org/sound-theme-freedesktop/tree/stereo | |
#/usr/bin/ogg123 -q /usr/share/sounds/freedesktop/stereo/dialog-information.oga | |
# Sound files: https://github.com/GNOME/gnome-control-center/tree/master/panels/sound/data/sounds | |
/usr/bin/ogg123 -q /usr/share/sounds/gnome/default/alert/glass.ogg | |
# Sound files: http://packages.ubuntu.com/source/trusty/all/ubuntu-touch-sounds | |
#/usr/bin/ogg123 -q /usr/share/sounds/ubuntu/notifications/Mallet.ogg | |
onlinewebradio=false | |
fi | |
# Delay allow time for notification to play on WebRadio. | |
sleep 2 | |
# Send text to speech to WebRadio. | |
vartts=$1 | |
log_file="ttslog.txt" | |
# Check for text to send to TTS engines. | |
if [[ -n "$vartts" ]]; then | |
# Write to log file for debugging. | |
echo "$( date +%s ) $vartts" >> ${log_file} | |
# If we are online then use online TTS services, if not use local resources. | |
if [ $online == true ]; then | |
if [ $onlinewebradio == true ]; then | |
/usr/bin/curl --data "station=api.voicerss.org/?f=32khz_16bit_stereo%26key=29334415954d491b85535df4eb4dd821%26hl=en-us%26src="$va$ | |
#http://$webradio/?station='http://translate.google.com/translate_tts?client=tw-ob&ie=UTF-8&tl=en&q='$vartts > /dev/null 2>&1 | |
echo "/usr/bin/curl --data station=api.voicerss.org/?f=32khz_16bit_stereo%26key=29334415954d491b85535df4eb4dd821%26hl=en-us%26src$ | |
#echo "/usr/bin/curl http://$webradio/?station='http://translate.google.com/translate_tts?client=tw-ob&ie=UTF-8&tl=en&q=$vartts'"$ | |
else | |
/usr/bin/mpg123 "http://translate.google.com/translate_tts?client=tw-ob&ie=UTF-8&tl=en&q=$vartts" > /dev/null 2>&1 | |
fi | |
else | |
pico2wave -w /opt/openhab/conf/html/tts.wav "$vartts" | |
if [ $onlinewebradio == true ]; then | |
/usr/bin/curl --data "station="$openhab"/static/tts.wav" $webradio > /dev/null 2>&1 | |
else | |
play tts.wav > /dev/null 2>&1 | |
fi | |
# Alternative wav player. | |
#aplay tts.wav > /dev/null 2>&1 | |
# Alternative TTS | |
#echo "$reminder" | /usr/bin/espeak | |
fi | |
else | |
echo "Argument error, require some text!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment