def testRec(): silent, sample_width, data = record(5) data = pack('<' + ('h'*len(data)), *data) wf = wave.open('/home/pi/Room/stt.wav', 'wb') wf.setnchannels(1) wf.setsampwidth(sample_width) wf.setframerate(RATE) wf.writeframes(data) wf.close() print 'parse',parseSTT.parse()
def rec(duration): silent, sample_width, data = record(duration) data = pack('<' + ('h'*len(data)), *data) wf = wave.open('stt.wav', 'wb') wf.setnchannels(1) wf.setsampwidth(sample_width) wf.setframerate(RATE) wf.writeframes(data) wf.close() if not silent: return parseSTT.parse() else: return True
def rec(queue): while True: #eventually record length wont matter silent, sample_width, data = record(5) data = pack('<' + ('h'*len(data)), *data) wf = wave.open('/home/pi/Room/stt.wav', 'wb') wf.setnchannels(1) wf.setsampwidth(sample_width) wf.setframerate(RATE) wf.writeframes(data) wf.close() #maybe also do this async if not silent: translations = parseSTT.parse() queue.put(translations) #indicate this came from mic queue.put("rec")
import subprocess as sub from speak import speak from rec import rec import parseSTT import processSTT import re while True: speak("When do you want the alarm for?") silent=rec(6) if not silent: parseSTT.parse() file = open("./stt.txt",'r') for line in file: print line if re.search("[0-9]+\shours\s[0-9]+\sminutes",line): words=line.split(" ") hr=words[0] min=words[2] print hr,min,period speak("alarm will be set for"+line) cmd="(crontab -l ; echo "+min+" "+hr+" * * * ~/Room/commands/alarm.sh) | sort - | uniq - | crontab -" print cmd sub.call(cmd,shell=True) quit() speak("sorry, I did not hear any valid times. try again")