for those who may wish to build a OpenwrtAI. here are a few scripts to get you started . you will need to install python speech recongnistion and TTS
see this thread for details on how to do that.
these are the basic scripts that are require.
speak script:
!/usr/bin/env python
# need gTTS and mpg123
# pip install gTTS
# opkg install mpg123
from gtts import gTTS
import os
import sys
# define variables
s = sys.argv[1]
file = "/tmp/audio.mp3"
# initialize tts, create mp3 and play
tts = gTTS(s, 'com')
tts.save(file)
os.system("mpg123 " + file)
read script
#!/bin/bash
while read -r line;do
echo -e "$line"
./google $line
done <$1
google - part of read -
#!/bin/bash
python3 speak "$*" #> /dev/null 2>&1
gtrans
#!/usr/bin/env python
import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile('/tmp/mic.wav') as source:
audio = r.record(source, duration=60)
command = r.recognize_google(audio)
text_file = open("Output.txt", "w")
text_file.write(command)
text_file.close()
AI - this is the bash script that you run. to be enabled by a button fuction, i use a zigbee button and zigbee keychain button( via domoticz) to run it, simply push it. then OpenWrtAI will initiate - you have pure privacy . unlike other AI's they listen to everything you say all the time and are log on remoter severs. OpenWrtAI will only provide information when you want it too.
AI-
#!/bin/bash
chroot /root/VLC_JULIUS/ /bin/bash ./kill.sh
pkill mpg123
A=0
B=0
while [[ $A < 3 ]]; do
wget -q --spider http://google.com
#______________onlineor offline speech engine________________#
if [ $? -eq 0 ]; then
if [ $B -eq 0 ];then
python speak " what can I do for you" > /dev/null 2>&1
B=1
fi
arecord -f S16_LE -d 3 -r 8000 /tmp/mic.wav > /dev/null 2>&1
#espeak "one moment" > /dev/null 2>&1
python speak "one moment" > /dev/null 2>&1
./gtrans.py > /tmp/stt # > /dev/null 2>&1
Output=$(cat /tmp/stt | sed -s '1d' | grep transcript | head -n 1 | sed "s/'transcript': //g" |sed "s/},//g" |sed 's/^ *//' |sed 's/}],//' | sed 's/{.*, //' ) #
# echo "Online"
else
if [ $B -eq 0];then
espeak " what can I do for you" > /dev/null 2>&1
B=1
fi
arecord -f S16_LE -d 3 -r 8000 /tmp/mic.wav > /dev/null 2>&1
espeak "one moment" > /dev/null 2>&1
rm /tmp/stt2
python test.py /tmp/mic.wav >>/tmp/stt2
cat /tmp/stt2 | grep '"text" :' | sed 's/ "text" : //g' | sed 's/""//g' | sed 's/"the"//g' | sed '/^\s*$/d'
voice=espeak
# echo "Offline"
fi
#__________________END _________________________#
echo $Output
NO_WHITESPACE="$(echo -e "${Output}" | sed 's/$/-1/' | tr -d ' ' | sed "s/'//g" )"
echo $NO_WHITESPACE
####################### PHRASE FUNCTION ###########
if [ $NO_WHITESPACE == 'playmusic-1' ]
then
echo "playing "
cd /MEDIA/Audio
find -iname '*.mp3' | mpg123 -Z -@ -
A=3
elif [ $NO_WHITESPACE == 'playCityFM-1' ]
then
echo "playing citi fm "
chroot /root/VLC_JULIUS /bin/bash VLC.sh 'http://rogers-hls.leanstream.co/rogers/win921.stream/icy'
sleep 2
mpg123 http://127.0.0.1:9090/stream
A=3
elif [ $NO_WHITESPACE == 'playKissFM-1' ]
then
echo "playing kiss fm "
chroot /root/VLC_JULIUS /bin/bash VLC.sh 'https://rogers-hls.leanstream.co/rogers/win1023.stream/playlist.m3u8'
sleep 2
mpg123 http://127.0.0.1:9090/stream
A=3
elif [ $NO_WHITESPACE == 'playPeggyFM-1' ]
then
echo "playing peggy fm "
chroot /root/VLC_JULIUS /bin/bash VLC.sh 'http://live.leanstream.co/CJGVFM?'
sleep 2
mpg123 http://127.0.0.1:9090/stream
A=3
elif [ $NO_WHITESPACE == 'playPower97-1' ]
then
echo "playing power fm "
chroot /root/VLC_JULIUS /bin/bash VLC.sh 'https://live.leanstream.co/CJKRFM'
sleep 2
mpg123 http://127.0.0.1:9090/stream
A=3
elif [ $NO_WHITESPACE == 'playVirginRadio-1' ]
then
echo "playing power fm "
chroot /root/VLC_JULIUS /bin/bash VLC.sh 'https://18183.live.streamtheworld.com/CKMMFM.mp3'
sleep 2
mpg123 http://127.0.0.1:9090/stream
A=3
elif [ "$NO_WHITESPACE" == 'weatheralert-1' ] || [ "$NO_WHITESPACE" == 'weatheralerts-1' ]
then
echo " weather alert"
./read /tmp/wstatement
A=3
elif [ "$NO_WHITESPACE" == 'readbook-1' ]
then
python speak " I have a selection of books that i can read - which one would you like"
python speak " dracula"
python speak "emma"
python speak "frankenstein"
sleep 2
python speak "which book would you like?"
while [[ $A < 3 ]]; do
arecord -f S16_LE -d 3 -r 8000 /tmp/mic.wav > /dev/null 2>&1
python speak "one moment" > /dev/null 2>&1
./gtrans.py > /tmp/stt # > /dev/null 2>&1
Output=$(cat /tmp/stt | sed -s '1d' | grep transcript | head -n 1 | sed "s/'transcript': //g" |sed "s/},//g" |sed 's/^ *//' |sed 's/}],//' | sed 's/{.*, //' ) #
echo $Output
N_WHITESPACE="$(echo -e "${Output}" | sed 's/$/-1/' | tr -d ' ' | sed "s/'//g" )"
echo $N_WHITESPACE
if [ "$N_WHITESPACE" == 'Frankenstein-1' ]; then
python speak " okay, I will read frankenstien"
sleep 2
./read ebook/frankenstein
elif [ "$N_WHITESPACE" == 'Emma-1' ]; then
python speak " okay, I will read emma"
sleep 2
./read ebook/emma
elif [ "$N_WHITESPACE" == 'Dracula-1' ]; then
python speak " okay, I will read dracula"
sleep 2
./read ebook/dracula
else
echo "oops---1"
if [ $A == 2 ]; then
sleep 2
((A++))
else
python speak "sorry, Please repeat "
((A++))
fi
fi
done
else
echo "oops"
if [ $A == 2 ]; then
sleep 2
python speak " Sorry I do not understand, good bye"
((A++))
else
python speak "sorry, Please repeat "
((A++))
fi
fi
############## END of PHRASE ###################
done
######
now since openwrt mediaplayers are geting a little long in the tooth. they work with very few media streams to get around this we use VLC in chroot to transcode to an appropriate codex
for this you need to create the userspace
#!/bin/sh
THIS_CHROOT="/root/VLC_JULIUS"
#chroot is not there, build it
if [ ! -d "$THIS_CHROOT" ]; then
debootstrap --arch amd64 bullseye "$THIS_CHROOT"
chroot "$THIS_CHROOT" /bin/bash -c "apt install -y curl build-essential git vim libsdl2-dev libasound2-dev zlib1g-dev wget tar unzip libsndfile1 libsndfile1-dev vlc"
fi
chroot "$THIS_CHROOT" /bin/bash -c "mount -t proc proc /proc && \
mount -t sysfs sys /sys && \
apt-get install -y vlc && \
mkdir /opt/julius && \
git clone https://github.com/palles77/julius.git && \
cd julius && \
chmod +x configure && \
./configure --enable-words-int --prefix=/opt/julius --enable-fork && \
make && \
make install && \
wget https://versaweb.dl.sourceforge.net/project/juliusmodels/ENVR-v5.4.Dnn.Bin.zip && \
unzip ENVR-v5.4.Dnn.Bin.zip -d /opt/julius && \
rm ENVR-v5.4.Dnn.Bin.zip && \
wget http://www.repository.voxforge1.org/downloads/Nightly_Builds/AcousticModel-2021-01-25/HTK_AcousticModel-2021-01-25_8kHz_16bit_MFCC_O_D.zip && \
unzip HTK_AcousticModel-2021-01-25_8kHz_16bit_MFCC_O_D.zip -d /opt/julius/vox && \
rm HTK_AcousticModel-2021-01-25_8kHz_16bit_MFCC_O_D.zip"
you can stop the build after vlc install.. as the rest is related to julius for offline translation
apt-get install -y vlc && \ just delete everything after it and remove && \ and changing it to "
then you need to put these two scripts into your chroot folder
kill.sh
#!/bin/bash
pkill vlc && exit
and VLC.sh
#!/bin/bash
sudo -H -u nobody cvlc $1 --sout="#transcode{vcodec=none,acodec=mp3,ab=64,channels=2,samplerate=44100}:http{mux=mp3,dst=:9090/stream}" --sout-keep --loop >/dev/null 2>&1 & echo "" > /tmp/tmp
exit 0
the hardest thing about getting internet radio to work is finding a site to scrape it from usually you find them in the page source page.
the easiest way when determining what you need as a call condition, is run AI script and when it ask you what you want to do, say it . and it will display what it thinks you are saying. it will ask you three times . just make sure the if condition matches also it is case sensitive
some of it related to my mycroft skills that one can find on github that I am adapting for this such as my gutenburg skill EVCAN skill if you live in Euope you use my metro weather skill for weather alerts
but all in all the AI works well and easy to set up . Mycroft can really annoying beeping allbtimes day and night . just to figure out how to get julius to be consistent for offline usage
okay have fun !