Voice commands - smx06/DIYorange GitHub Wiki
TODO: replace google voice recognition with Google Offline dict or Spinx: https://sourceforge.net/p/cmusphinx/discussion/help/thread/0fa4417e/ https://habrahabr.ru/post/237589/
Install Voice synthesis
apt-get festival festvox-en
(or your language)
Make Festival config:
cd ~/
nano .festivalrc
add such strings:
(Parameter.set 'Audio_Command "aplay -Dplug:default -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
Test:
echo "Test" | festival --tts --language english
(needs from 5 to 30 sec for voice generation)
.sh
forecast.sh
URL='http://www.accuweather.com/en/ru/saint-petersburg/295212/weather-forecast/295212'
wget -q -O- "$URL" | awk -F' '/acm_RecentLocationsCarousel.push/{print "Now is", $12, "Celsius" }'| head -1
sayforecast.sh
#!/bin/sh /root/0/forecast.sh | festival --tts --language english
launcher.sh
while [ true ] do arecord -B --buffer-time=1000000 -f dat -r 16000 -d 4 -D plug:default voice.wav filesize=$(stat -c%s "voice.wav") echo $filesize python3 go.py rm voice.wav echo completed done
go.py
#! /usr/bin/env python
#--coding:utf-8--
import os
import speech_recognition as sr
r = sr.Recognizer()
with sr.WavFile("voice.wav") as source: # use "test.wav" as the audio source
audio = r.record(source) # extract audio data from the file
try:
t = r.recognize_google(audio,language = "en-En", key = "....")
print(t) # recognize speech using Google Speech Recognition
except LookupError: # speech is unintelligible
print("Could not understand audio")
if t == 0:
print("Error")
elif t==("weather"):
print ("Forecast:")
os.system("amixer set 'Lineout volume control' 50%")
os.system("/root/0/sayforecast.sh")
elif t==("stop"):
print("Stop")
os.system ("mpc clear")