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
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()