def speech_do_work(boolean): if boolean: #if I say "turn on speech" #Jarvis will listen to anything I say and print it speech.listenforanything(speech_callback) else: #if I say "turn off speech" #it will wait for me to say "turn on speech" speech.listenfor(["turn on speech"], speech_callback)
def aom_listener(): import speech def do_aom(phrase, listener): if phrase == 'green': aom = 'GreenAOM' elif phrase == 'red': aom = 'MatisseAOM' elif phrase == 'pulse': aom = 'PulseAOM' elif phrase == 'yellow': aom = 'YellowAOM' elif phrase == 'stop': print 'stop listening' listener.stoplistening() return elif phrase == 'servo': print 'PMservo flip' ins = qt.instruments['PMServo'] if ins.get_position() == ins.get_in_position(): ins.move_out() else: ins.move_in() return elif phrase == 'power': power = '{:.0f} nano waat'.format( qt.instruments['powermeter'].get_power() * 1e9) print 'power: ', power speech.say(power) return else: print 'Not understood' if qt.instruments[aom].get_power() == 0.: print 'Turning on', aom qt.instruments[aom].turn_on() else: print 'Turning off', aom qt.instruments[aom].turn_off() #How can i remove windows commands from pyspeech windows recognition? #For example if i wanted for my program to open up notepad i would say #"Open notepad", but then windows will also open up notepad for me too. #How can i disable this so that my program is the only one running commands? #in lib/site_packages/speech.py #On line 66 change the code to: #_recognizer = win32com.client.Dispatch("SAPI.SpInProcRecognizer") #_recognizer.AudioInputStream = win32com.client.Dispatch("SAPI.SpMMAudioIn") #And on line 112 change the code to: #_ListenerBase = win32com.client.getevents("SAPI.SpInProcRecoContext") #This should prevent the windows commands from running while also not showing the widget which comes up. Good luck! listener = speech.listenfor( ['red', 'yellow', 'green', 'pulse', 'stop', 'power', 'servo'], do_aom)
def __start__(self,words1,level1,words2,level2,fillerWords,logging): fillerWordList = fillerWords.split(',') wordList1 = words1.split(',') wordList2 = words2.split(',') self.wordList = fillerWordList + wordList1 + wordList2 if logging: for word in self.wordList: print word def followUp(plugin): Event().wait(3) plugin.counter -= 1 if plugin.counter <= 0: plugin.TriggerEvent("DIE") plugin.counter = 0 def callback(phrase, listener,engineConfidence,actualConfidence): self.counter += 1 if phrase in wordList1: if engineConfidence*100 >= level1 and actualConfidence>= 0: print phrase + " "+ str(engineConfidence*100) self.TriggerEvent(phrase) else: if logging: print phrase + " "+ str(engineConfidence*100) elif phrase in wordList2: if engineConfidence*100 >= level2 and actualConfidence>= 0: print phrase + " "+ str(engineConfidence*100) self.TriggerEvent(phrase) else: if logging: print phrase + " "+ str(engineConfidence*100) Thread(target=followUp, args=(self,)).start() speech.listenfor(self.wordList,callback)
# input() waits for user input. The prompt text is optional. spoken_text = speech.input("Say something, user!") print ("You said: %s" % spoken_text) # You can limit user input to a set of phrases. spoken_text = speech.input("Are you there, user?", ["Yes", "No", "Shut up, computer."]) print ("You said: %s" % spoken_text) # If you don't want to wait for input, you can use listenfor() to run a callback # every time a specific phrase is heard. Meanwhile your program can move on to other tasks. def L1callback(phrase, listener): print ("Heard the phrase: %s" % phrase) # listenfor() returns a Listener object with islistening() and stoplistening() methods. listener1 = speech.listenfor(["any of", "these will", "match"], L1callback) # You can listen for multiple things at once, doing different things for each. def L2callback(phrase, listener): print ("Another phrase: %s" % phrase) listener2 = speech.listenfor(["good morning Michael"], L2callback) # If you don't have a specific set of phrases in mind, listenforanything() will # run a callback every time anything is heard that doesn't match another Listener. def L3callback(phrase, listener): speech.say(phrase) # repeat it back if phrase == "stop now please": # The listener returned by listenfor() and listenforanything() # is also passed to the callback. listener.stoplistening() listener3 = speech.listenforanything(L3callback)
speech.say("I am speaking out loud.") # input() waits for user input. The prompt text is optional. spoken_text = speech.input("Say something, user!") print "You said: %s" % spoken_text # You can limit user input to a set of phrases. spoken_text = speech.input("Are you there, user?", ["Yes", "No", "Shut up, computer."]) print "You said: %s" % spoken_text # If you don't want to wait for input, you can use listenfor() to run a callback # every time a specific phrase is heard. Meanwhile your program can move on to other tasks. def L1callback(phrase, listener): print "Heard the phrase: %s" % phrase # listenfor() returns a Listener object with islistening() and stoplistening() methods. listener1 = speech.listenfor(["any of", "these will", "match"], L1callback) # You can listen for multiple things at once, doing different things for each. def L2callback(phrase, listener): print "Another phrase: %s" % phrase listener2 = speech.listenfor(["good morning Michael"], L2callback) # If you don't have a specific set of phrases in mind, listenforanything() will # run a callback every time anything is heard that doesn't match another Listener. def L3callback(phrase, listener): speech.say(phrase) # repeat it back if phrase == "stop now please": # The listener returned by listenfor() and listenforanything() # is also passed to the callback. listener.stoplistening() listener3 = speech.listenforanything(L3callback)
mail.expunge() #****sending from computer**** import smtplib server = smtplib.SMTP( "smtp.gmail.com", 587 ) server.starttls() server.login( '*****@*****.**', '15963212') def sendmess(string): server.sendmail( '8589976724', '*****@*****.**', string ) if __name__ == '__main__': Popen("C:/Users/James/Desktop/Jarvis_3.exe", shell = True) #stderr=child_conn) listener = speech.listenfor(["turn on speech", "Turn on speech", "Turn off speech", "turn off speech", "turnoff speech", "Turnoff speech"], speech_callback) unsmess() ## proc_list=[] ## # Launch Proc1 ## #proc_list.append( launch_proc(Console, "Console") ) ## proc_list.append( launch_proc(speech_callback, "Voice",(speech_parent, speech_child)) ) ## pJarvis = CallJarvis() ## Jarvis_in = pJarvis.stdin ## Jarvis_out = pJarvis.stdout ## while(1): ## ##(1) Print out the prompt of Jarvis ## print Jarvis_out.readline() ## for proc, parent_conn, name in proc_list:
pos = m.position() m.move(pos[0] + 200, pos[1]) elif phrase == "Mouse all the way to the right": m = PyMouse() m.position() pos = m.position() m.move(pos[0] + 1000, pos[1]) elif phrase == "Mouse all the way to the left": m = PyMouse() m.position() pos = m.position() m.move(pos[0] - 1000, pos[1]) elif phrase == "Mouse to the left a little": m = PyMouse() m.position() pos = m.position() m.move(pos[0] - 10, pos[1]) elif phrase == "Mouse to the left a lot": m = PyMouse() m.position() pos = m.position() m.move(pos[0] - 200, pos[1]) Ll = speech.listenfor(["Mouse Down", "Mouse all the way to the right", "Mouse all the way to the left", "Right Click", "Mouse to the left a little", "Double Click", "Mouse to the right a lot", "Mouse to the left a lot", "Mouse to the right a little", "Mouse Up", "Mouse down a little", "Mouse to the right", "Mouse Up a little", "Mouse to the left", "Click"], Get) while Ll.islistening(): time.sleep(.5)
elif phrase == "get me the weather forecast": speech.say("Getting weather forecast. Please wait...!") print(phrase) speech.say("This week's weather forecast:") for item in Weather.getWeatherForecast(): speech.say(item) elif phrase == "any new mails": check_mails() print(phrase) elif phrase == "morning greetings": morning_greetings() else: print(phrase) speech.say("Could not understand, please repeat") listner = speech.listenfor([ 'jarvis', 'jaiss', 'turn off', 'how are you', 'read news', 'stop', 'show my feeds', 'what is the current time', 'are you up', 'how is the weather outside', 'get me the weather forecast', 'any new mails', '*', 'morning greetings' ], handleCallback) import time while listner.islistening(): time.sleep(1) #print "Waiting for Command"
import speech import serial import time import sys s=serial.Serial(sys.argv[1]) def respuesta(f, l): if f == "Prende": s.write("1") print("ON") else: s.write("0") print("OFF") l=speech.listenfor(['Prende','Apaga'],respuesta) raw_input()
import speech import serial import time import sys s = serial.Serial(sys.argv[1]) def respuesta(f, l): if f == "Prende": s.write("1") print("ON") else: s.write("0") print("OFF") l = speech.listenfor(['Prende', 'Apaga'], respuesta) raw_input()
if phrase == "turn off kat": cs.speak("Turning off.") listener.stoplistening() elif phrase == "what is your name": cs.speak("My name is Kat, the knowledge automation tool.") elif phrase == "What is the time kat": currentHour = int(time.strftime("%H")) endTimeStr = " A M" if currentHour > 12: endTimeStr = " P M" currentHour = currentHour % 12 elif currentHour == 0: currentHour = 12 currentHour = str(currentHour)+" " currentMinute = time.strftime("%M") cs.speak("The current time is "+currentHour + currentMinute + endTimeStr) elif phrase == "how are you kat": cs.speak("I am well, thank you.") elif phrase == "what is the weather like kat": cs.speak(getWeather()) else: cs.speak("You said %s" % phrase) listener = speech.listenfor( ['turn off kat', 'What is the time kat', 'how are you kat', 'who is my bow bay','what is your name', 'what is the weather like kat'], response) # Concurrent process while listener.islistening(): time.sleep(1) print "Listening..."
speech.say("Getting weather forecast. Please wait...!") print (phrase) speech.say("This week's weather forecast:") for item in Weather.getWeatherForecast(): speech.say(item) elif phrase == "any new mails": check_mails() print (phrase) elif phrase == "morning greetings": morning_greetings() else: print (phrase) speech.say("Could not understand, please repeat") listner = speech.listenfor(['jarvis', 'jaiss', 'turn off', 'how are you', 'read news', 'stop' , 'show my feeds', 'what is the current time', 'are you up', 'how is the weather outside', 'get me the weather forecast', 'any new mails', '*', 'morning greetings'], handleCallback) import time while listner.islistening(): time.sleep(1) #print "Waiting for Command"