Sep-16-2020, 08:47 PM
so here I'm working on follow up if statements it works good with input() as it stands but what im trying to do is when use audio to ask the follow up questions and exe them.
I can get a response and exe a command with audio no problem however when im trying to ask a follow up question I can't get it to work
for example
wake word = ada
she is listening now
if I say 'lights' she turns them on
but I want her to say right after that 'would you like me to dim them?
if I say 'yes' she will use the 50% dim cmd
I can get this to work using the input() way I have set up below just not with audio any idea
I can get a response and exe a command with audio no problem however when im trying to ask a follow up question I can't get it to work
for example
wake word = ada
she is listening now
if I say 'lights' she turns them on
but I want her to say right after that 'would you like me to dim them?
if I say 'yes' she will use the 50% dim cmd
I can get this to work using the input() way I have set up below just not with audio any idea
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
from phue import Bridge from os import system import speech_recognition as sr import warnings import random b = Bridge( 'xxx.xxx.x.x' ) # bridge ip adress b.connect() # connect to the bridge b.get_api() warnings.filterwarnings( 'ignore' ) def recordaudio(): #record audio r = sr.Recognizer() # creating recognizer # open microphone and start recording with sr.Microphone() as source: print ( 'listening:' ) # for testing perpouses #r.pause_threshold = .7 audio = r.listen(source) # use google speech recegnizor data = '' #the audio that is said try : data = r.recognize_google(audio) print ( 'you said: ' + data) # 'you said' + the data that was said except sr.UnknownValueError: print ( 'google speech recognition could not understand the audio, unknown error' ) except sr.RequestError as e: print ( 'request results from google speech recognition service error' + e) return data #-------------function to get the AI response---------# def assistantResponse (text): print (text) system( "say {}" . format (text)) #--------------what is your name-------------# def name(text): WAKE_WORD = [ 'what is your name' ] text = text.lower() for phrase in WAKE_WORD: if phrase in text: return True return False #-------------creating a function for wake word(s) or phrase------------# def wakeWord(text): WAKE_WORDS = [ 'eta' , 'ada' , 'hey ada' , 'hi ada' , 'aida' , 'haida' ,] #list of wake words text = text.lower() #converting text to all lower case words #check to see if the users command or text contains a wake word/phrase for phrase in WAKE_WORDS: if phrase in text: return True #if the wake word isnt found in the text from the loop it returns false return False def my_room_light(My_room_l, My_room_l_bri): b.set_light([ 1 ], 'on' , My_room_l) b.set_light([ 1 ], 'bri' , My_room_l_bri) # num = input("Enter number :") # print(num) # name1 = input("Enter name : ") # print(name1) # # # Printing type of input value # print("type of number", type(num)) # print("type of name", type(name1)) def greeting(text): GREETING_INPUTS = [ 'hi' , 'hey' , 'hello' , 'greetings' ,] GREETING_RESPONSES = [ 'hi' , 'hello how are you' , 'hello' , 'hi how are you' ] #if the users input is a greeting then return a randomly chosen greeting response for word in text.split(): if word.lower() in GREETING_INPUTS: return random.choice(GREETING_RESPONSES) + '.' #if no greeting is detected then return an empty string return '' def yes(text): YES = [ 'yes' ] text = text.lower() for phrase in YES: if phrase in text: return True return False def no(text): NO = [ 'no' ] text = text.lower() for phrase in NO: if phrase in text: return True return False def lower(text): HIGHER = [ 'higher' , 'brighter' , ] text = text.lower() for phrase in HIGHER: if phrase in text: return True return False def higher(text): LOWER = [ 'lower' , 'dim' , 'dimmer' ,] text = text.lower() for phrase in LOWER: if phrase in text: return True return False while True : # ---------------always listen to wake word--------------# # record the audio # text = recordaudio() # response = '' # -----------start check for wake word or phrase-----------# text = input ( 'cmd: ' ) # if (wakeWord(text) or name(text) == True): # added or name(text) # # check for greeting by user # response = response + greeting(text) if 'on' in text: my_room_light( True , 254 ) # response = 'would you like me to dim them:' text = input ( 'would you like me to dim them:' ) if higher(text) = = True : print (text) my_room_light( True , 191 ) if lower(text) = = True : print (text) my_room_light( True , 64 ) if no(text) = = True : print ( 'okay' ) if yes(text) = = True : my_room_light( True , 127 ) print (text) text = input ( 'sufficient?:' ) if no(text) = = True : text = input ( 'would you like me to make them lower?' ) if higher(text) = = True : print (text) my_room_light( True , 191 ) elif yes(text) = = True : my_room_light( True , 64 ) elif yes(text) = = True : print (text) elif higher(text) = = True : print (text) my_room_light( True , 191 ) elif lower(text) = = True : print (text) my_room_light( True , 64 ) # assistantResponse() |