Пример #1
0
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)
Пример #2
0
def initialize_home():
    global user_id
    user_id = pyfaces.recognize_face()
    print(user_id)
    #user_id = 'xyzxxxx'
    global Mode
    global done
    global turn_off
    TrainingDictionary = load_training_data()
    print(TrainingDictionary)
    if (user_id in TrainingDictionary):
        print("You have already visited i-home. The home is trained by your habit. Do you like the home to run in your personalized mode. say YES or NO")
        speech.say("You have already visited i-home. The home is trained by your habit. Do you like the home to run in your personalized mode. say YES or NO")
        listener = speech.listenforanything(callback)
        done=0
        while done!=1:
                continue            
        
        # it will go in while loop only when default mode is selected
        if Mode=='default':
            print 'in default mode'
            while listener.islistening():
                text = raw_input("> ")
                #text = 'asd'
                if turn_off==1:
                    sys.exit()
                elif text == "turn off":
                    listener.stoplistening()
                    sys.exit()
                else:
                    speech.say(text)
            #print(" I am outside the callback")
        #print(Mode)
        elif Mode=='personal':
            print 'in personal mode'
            spoken_command1 = TrainingDictionary[user_id][0]
            spoken_command2 = TrainingDictionary[user_id][1]
            #print(spoken_command1)
            #print(spoken_command2)
            activate_home(spoken_command1, spoken_command2)
    else:
        print 'New user found, set to defualt spoken mode'
        speech.say('New user found, set to defualt spoken mode')
        #for new user
        listener = speech.listenforanything(callback)
        # it will go in while loop only when default mode is selected
        while listener.islistening():
            text = raw_input("> ")
            if turn_off==1:
                    sys.exit()
              
            elif text == "turn off":
                listener.stoplistening()
                sys.exit()
            else:
                speech.say(text)
Пример #3
0
def unblockListen():

    listener = speech.listenforanything(response)

    # Your program can do whatever it wants now, and when a spoken phrase is heard,
    # response() will be called on a separate thread.

    while listener.islistening():
        time.sleep(1)
        print "Still waiting..."
Пример #4
0
def unblockListen():

    listener = speech.listenforanything(response)

# Your program can do whatever it wants now, and when a spoken phrase is heard,
# response() will be called on a separate thread.

    while listener.islistening():
        time.sleep(1)
        print "Still waiting..."
Пример #5
0
def main():
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption("Stoneage Game")
    tablero = Tablero(screen)
    jugador = Jugador(screen)
    listener = speech.listenforanything(jugador.callback)
    pygame.mixer.init()    

    while not jugador.ganador() or listener.listening():
        for eventos in pygame.event.get():
            if eventos.type == QUIT:
                sys.exit(0)
            jugador.mover(tablero, screen)
    tablero.pantalla_fin()
    return 0
Пример #6
0
	def createwindow(self, controller):
		def callback1(self,phrase):
			print ": %s" % phrase
			global dict 
			p=re.compile('.*Play.*',re.IGNORECASE)
			if p.match(phrase):
				#print "ding ding"
				#listener.stoplistening()
				controller.show_frame(PageOne)
		label = tk.Label(self, text="Welcome to DIGIWAR!!", font=LARGE_FONT)
		label.pack(pady=10,padx=10)

		button = tk.Button(self, text="Play Game",
							command=lambda: controller.show_frame(PageOne))
		button.pack()

		button2 = tk.Button(self, text="Instructions",
							command=lambda: controller.show_frame(PageTwo))
		button2.pack()
		
		
		listener1 = speech.listenforanything(callback1)
Пример #7
0
       # print(phrase.split())
        spoken_input = phrase.split()
       # print(spoken_input)
        spoken_command1 = spoken_input[0].lower()
        spoken_command2 = spoken_input[len(spoken_input) - 1].lower()
        #print(spoken_command1)
        #print(spoken_command2)
        activate_home(spoken_command1, spoken_command2)

##print "Anything you type, speech will say back."
##print "Anything you say, speech will print out."
##print "Say or type 'turn off' to quit."
##print

print "i-home is activated"
listener = speech.listenforanything(callback)


while listener.islistening():
    text = raw_input("> ")
    if text == "turn off":
        listener.stoplistening()
        sys.exit()
    else:
        speech.say(text)





Пример #8
0
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)

# All callbacks get automatically executed on a single separate thread.
# Meanwhile, you can just do whatever with your program, or sleep.
# As long as your main program is running code, Listeners will keep listening.

import time
while listener3.islistening(): # till "stop now please" is heard
  time.sleep(1)

assert speech.islistening() # to at least one thing
print ("Dictation is now stopped.  listeners 1 and 2 are still going.")

listener1.stoplistening()
print ("Now only listener 2 is going")
Пример #9
0
import speech
import time

response = speech.input("Say something, please.")
speech.say("You said " + response)


def callback(phrase, listener):
    if phrase == "再见":
        listener.stoplistening()
    speech.say(phrase)
    print(phrase)


listener = speech.listenforanything(callback)
while listener.islistening():
    time.sleep(.5)
Пример #10
0
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)

# All callbacks get automatically executed on a single separate thread.
# Meanwhile, you can just do whatever with your program, or sleep.
# As long as your main program is running code, Listeners will keep listening.

import time
while listener3.islistening(): # till "stop now please" is heard
  time.sleep(1)

assert speech.islistening() # to at least one thing
print "Dictation is now stopped.  listeners 1 and 2 are still going."

listener1.stoplistening()
print "Now only listener 2 is going"
	def __init__(self):
		print 'In Constructor'
		listener = speech.listenforanything(self.callback)
		print 'In constructor 2'
Пример #12
0
	def pressed(self, index):
		global flag,dict
		global mat,turn,MAX
		mat2=[x[:] for x in mat]
		if flag==1 :
			#print("number pressed", index)
			global id,Kmaxg,Kmaxb
			#print(mat[index/rsiz][index%rsiz],index/rsiz,index%rsiz)
			#print("\n ",mat)
			if mat[index/rsiz][index%rsiz]== -2 and turn==-1 and Kmaxg:
				mat2[index/rsiz][index%rsiz]= -3
				turn=1
				Kmaxg=Kmaxg-1
				self.buttons[index].configure(bg = "dark green")
			elif mat[index/rsiz][index%rsiz]== 2 and turn==1 and Kmaxb:
				mat2[index/rsiz][index%rsiz]= 3
				turn=-1
				Kmaxb=Kmaxb-1
				self.buttons[index].configure(bg = "dark blue")
			elif mat[index/rsiz][index%rsiz]==-1 and turn==-1 and id<MAX:
				id=id+1
				mat2[index/rsiz][index%rsiz]= -2
				turn=1
				self.buttons[index].configure(bg = "green",text=id)
				dict[id]=index
			elif mat[index/rsiz][index%rsiz]==1 and turn==1 and id<MAX:
				id=id+1
				mat2[index/rsiz][index%rsiz]= 2
				turn=-1
				self.buttons[index].configure(bg = "blue",text=id)
				dict[id]=index
			mat=[row[:] for row in mat2]
			#print("\n ",mat)
		elif flag==0 :
			if mat[index/rsiz][index%rsiz]!=5 or mat[index/rsiz][index%rsiz]!=-1 or mat[index/rsiz][index%rsiz]!=1 :
				#print("flag =0 number pressed", index)
				#print("\n ",mat)
				row_num=index/rsiz
				if mat[index/rsiz][index%rsiz]== -2 and turn==-1:					
					#print("green soldier clicked!! \n")
					while mat[index/rsiz][index%rsiz]==-1 or mat[index/rsiz][index%rsiz]==5 or mat[index/rsiz][index%rsiz]==-2 or mat[index/rsiz][index%rsiz]==-3 :
						index = index + 1
						if(index/rsiz!=row_num):
							index=index-1
							break
						#print("rn=",row_num,"i/rs=",index/rsiz)
					#print("green side ",index,index/rsiz,index%rsiz)
					turn=1
					mat2[index/rsiz][index%rsiz]=5
				elif mat[index/rsiz][index%rsiz]==2 and turn==1:
					while mat[index/rsiz][index%rsiz]==1 or mat[index/rsiz][index%rsiz]==5 or mat[index/rsiz][index%rsiz]==2 or mat[index/rsiz][index%rsiz]==3:
						index = index - 1
						if(index/rsiz!=row_num):
							index=index+1
							break
						#print("rn=",row_num,"i/rs=",index/rsiz)
					turn=-1
					#print("blue side",index,index/rsiz,index%rsiz)
					mat2[index/rsiz][index%rsiz]=5
				elif mat[index/rsiz][index%rsiz]== -3 and turn==-1:					
					#print("green soldier clicked!! \n")
					# index = index + 1
					while any([mat[index/rsiz][index%rsiz]==-1,mat[index/rsiz][index%rsiz]==5,mat[index/rsiz][index%rsiz]==-2,mat[index/rsiz][index%rsiz]==-3]):
						index = index + 1
						if(index/rsiz!=row_num):
							index=index-1
							break
						#print("rn=",row_num,"i/rs=",index/rsiz)
					#print("green side ",index,index/rsiz,index%rsiz)
					turn=1
					mat2[index/rsiz][index%rsiz]=5
					mat2[index/rsiz+1][index%rsiz]=5
					mat2[index/rsiz-1][index%rsiz]=5
				elif mat[index/rsiz][index%rsiz]==3 and turn==1:
					#index = index - 1
					while any([mat[index/rsiz][index%rsiz]==1,mat[index/rsiz][index%rsiz]==5,mat[index/rsiz][index%rsiz]==2,mat[index/rsiz][index%rsiz]==3]) :
						index = index - 1
						if(index/rsiz!=row_num):
							index=index+1
							break
						#print("rn=",row_num,"i/rs=",index/rsiz)
					turn=-1
					#print("blue side",index,index/rsiz,index%rsiz)
					mat2[index/rsiz][index%rsiz]=5
					mat2[index/rsiz+1][index%rsiz]=5
					mat2[index/rsiz-1][index%rsiz]=5
		elif flag==2 :
			if mat[index/rsiz][index%rsiz]!=5 or mat[index/rsiz][index%rsiz]!=-1 or mat[index/rsiz][index%rsiz]!=1 :
				#print("move up number pressed", index)
				#print("\n ",mat)
				if any([mat[index/rsiz][index%rsiz]== -2,mat[index/rsiz][index%rsiz]== -3]) and turn==-1:					
					#print("green soldier clicked!! \n")
					t=self.buttons[index].cget("text")
					t_up=self.buttons[index-rsiz%size].cget("text")
					self.buttons[index-rsiz%size].configure(text=t)
					del dict[t]
					dict[t]=index+rsiz % size
					self.buttons[index].configure(text=t_up)
					tex=mat[index/rsiz-1][index%rsiz];
					mat2[index/rsiz-1][index%rsiz]=mat[index/rsiz][index%rsiz];
					mat2[index/rsiz][index%rsiz]=tex;
					turn=1;
					#print(t)
					#print("green side ",index,index/rsiz,index%rsiz)
					
				elif any([mat[index/rsiz][index%rsiz]==2, mat[index/rsiz][index%rsiz]== 3]) and turn==1:					
					#print("blue soldier clicked!! \n")
					t=self.buttons[index].cget("text")
					t_up=self.buttons[index-rsiz%size].cget("text")
					self.buttons[index-rsiz%size].configure(text=t)
					del dict[t]
					dict[t]=index+rsiz % size
					self.buttons[index].configure(text=t_up)
					tex=mat[index/rsiz-1][index%rsiz];
					mat2[index/rsiz-1][index%rsiz]=mat[index/rsiz][index%rsiz];
					mat2[index/rsiz][index%rsiz]=tex;
					turn=-1;
					#print(tex)
					#print("blue side ",index,index/rsiz,index%rsiz)
					
		elif flag==3 :
			if mat[index/rsiz][index%rsiz]!=5 or mat[index/rsiz][index%rsiz]!=-1 or mat[index/rsiz][index%rsiz]!=1 :
				#print("move down number pressed", index)
				#print("\n ",mat)
				if any([mat[index/rsiz][index%rsiz]== -2, mat[index/rsiz][index%rsiz]== -3]) and turn==-1:					
					#print("green soldier clicked!! \n")
					t=self.buttons[index].cget("text")
					t_dn=self.buttons[index+rsiz % size].cget("text")
					self.buttons[index+rsiz %size].configure(text=t)
					del dict[t]
					dict[t]=index+rsiz % size
					self.buttons[index].configure(text=t_dn)
					tex=mat[index/rsiz+1][index%rsiz];
					mat2[index/rsiz+1][index%rsiz]=mat[index/rsiz][index%rsiz];
					mat2[index/rsiz][index%rsiz]=tex;
					turn=1;
					#print(tex)
					#print("green side ",index,index/rsiz,index%rsiz)
					
				elif any([mat[index/rsiz][index%rsiz]==2, mat[index/rsiz][index%rsiz]== 3]) and turn==1:					
					#print("blue soldier clicked!! \n")
					t=self.buttons[index].cget("text")
					t_dn=self.buttons[index+rsiz % size].cget("text")
					self.buttons[index+rsiz%size].configure(text=t)
					del dict[t]
					dict[t]=index+rsiz % size
					self.buttons[index].configure(text=t_dn)
					tex=mat[index/rsiz+1][index%rsiz];
					mat2[index/rsiz+1][index%rsiz]=mat[index/rsiz][index%rsiz];
					mat2[index/rsiz][index%rsiz]=tex;
					turn=-1;
					#print(tex)
					#print("blue side ",index,index/rsiz,index%rsiz)
		mat=[row[:] for row in mat2]
		#print dict
		#print("\n ",mat)
		for m in range(rsiz):
			for n in range(rsiz):
			#listener = speech.listenforanything(callback)
				if mat[m][n]==2:
					self.buttons[m*rsiz + n].configure(bg="blue")
				elif mat[m][n]==3:
					self.buttons[m*rsiz + n].configure(bg="dark blue")
				elif mat[m][n]==-2:
					self.buttons[m*rsiz + n].configure(bg="green")
				elif mat[m][n]==-3:
					self.buttons[m*rsiz + n].configure(bg="dark green") 
				elif mat[m][n]==5:
					self.buttons[m*rsiz + n].configure(bg="black")
				elif mat[m][n]==-1:
					self.buttons[m*rsiz + n].configure(bg="light green")
				elif mat[m][n]==1:
					self.buttons[m*rsiz + n].configure(bg="light blue")
		if turn ==-1:
			self.Turn2.configure(bg="green")
		elif turn==1:
			self.Turn2.configure(bg="blue")
		listener = speech.listenforanything(self.callback)
Пример #13
0
# -*- coding: utf-8 -*-
import time
import speech
import subprocess
import win32com.client
closeMainSystem = u"滚"
listenMusic = u"我好累"
Word = u"写文章"

def callback(phrase, listener):
    print(": %s" % phrase)
    if phrase == closeMainSystem:
        speech.say(u"主人奴婢这就咕噜咕噜滚下去")
        listener.stoplistening()
        sys.exit()
    elif phrase == listenMusic:
        speech.say(u"主人,奴婢这就为你来按摩")
        webbrowser.open_new("http://douban.fm/")
    elif phrase == Word:
        speech.say(u"主人我这就给您磨砚")
        os.popen(
            "D:\Program Files (x86)\Microsoft Office\Office15\2052\QuickStyles\word2013.dotx"
        )

listener = speech.listenforanything(callback)
while listener.islistening():
    text = input()
    if text == u"不要语音了":
        listener.stoplistening()
        sys.exit()
Пример #14
0
# -*- coding: utf-8 -*-
import time
import speech
import subprocess
import win32com.client

closeMainSystem =u"滚"
listenMusic =u"我好累"
Word =u"写文章"

def callback(phrase, listener):
    print(": %s"%phrase)
    if phrase ==closeMainSystem:
        speech.say(u"主人奴婢这就咕噜咕噜滚下去")
        listener.stoplistening()
        sys.exit()
    elif phrase ==listenMusic:
        speech.say(u"主人,奴婢这就为你来按摩")
        webbrowser.open_new("http://douban.fm/")
    elif phrase ==Word:
        speech.say(u"主人我这就给您磨砚")
        os.popen("D:\Program Files (x86)\Microsoft Office\Office15\2052\QuickStyles\word2013.dotx")

listener =speech.listenforanything(callback)
while listener.islistening():
    text =input()
    if text ==u"不要语音了":
        listener.stoplistening()
        sys.exit()
    else:
	def __init__(self):
		listener = speech.listenforanything(self.callback)