def listen(device_id, sample_rate, chunk_size, r, driver, source, flag=False): # r.adjust_for_ambient_noise(source) r.pause_threshold = 0.8 print("say your sentence after the beep") time.sleep(1.2) playsound('beep.wav') #listens for the user's input text = "" try: audio = r.listen(source) text = r.recognize_google(audio) #error occurs when google could not understand what was said except sr.UnknownValueError: print("Google Speech Recognition could not understand audio") except sr.RequestError as e: print("Could not request results from Google") if "back" in text: if driver: tts.engine.stop() # driver.execute_script("window.history.go(-1)") tts.engine.disconnect() from main import main_loop main_loop() print("Interpreted as %s"%text) return text
def reg_func(*args): #data_base = sql.connect(host='localhost',user='******',passwd='password',database='login_app') data_base = sql.connect(host='sql12.freemysqlhosting.net', port=3306, user='******', passwd='XlRVrGbdRf', database='sql12372553') c = data_base.cursor() name = name_entry.get().title() user = user_entry.get() password = pass_entry.get() if name != '' and user != '' and password != '': c.execute('select Username from log_details') l = c.fetchall() ex_t = False for i in l: if user == i[0]: ex_t = True break else: ex_t = False if ex_t == True: mb.showerror('Register', f'{user} Already Exist.') else: c.execute( f'insert into log_details values("{name}","{user}","{password}","0.png")' ) data_base.commit() name_entry.delete(0, END) user_entry.delete(0, END) pass_entry.delete(0, END) global username_name username_name = name reg.destroy() f = open('isLog.txt', 'w') #to_write = 'logged in,'+username_name # for development purpose to_write = 'logged off' f.write(to_write) f.close() main.main_loop(username_name) else: mb.showerror('UniChat', 'Please Fill All The Fields.')
def log_func(*args): #data_base = sql.connect(host='localhost',port=3306,user='******',passwd='password',database='login_app') data_base = sql.connect(host='sql12.freemysqlhosting.net', port=3306, user='******', passwd='XlRVrGbdRf', database='sql12372553') c = data_base.cursor() user = user_entry.get() password = pass_entry.get() try: c.execute( f'select Password from log_details where Username = "******" ') b = c.fetchall() for i in b: passw = i[0] if password == passw: c.execute( f'select name from log_details where Username= "******"') b = c.fetchall()[0][0] username_name = b resp.configure(text=f'Login Successful\n Welcome {b} ', fg='green') log.destroy() f = open('isLog.txt', 'w') # for development purpose #to_write = 'logged in,'+b to_write = 'logged off' f.write(to_write) f.close() main.main_loop(b) else: resp.configure(text='Wrong Password', fg='red') except UnboundLocalError: resp.configure(text=f'Username {user} Does Not Exist', fg='red')
def get(): inkey = _Getch() while(1): k=inkey() if k!='':break if k=='\x1b[A': print( "up") elif k=='\x1b[B': print("down") elif k=='\x1b[C': print("right") elif k=='\x1b[D': print("left "+ str(k)) tts.engine.stop() tts.engine.disconnect() from main import main_loop main_loop() # (google.main.driver or wiki.driver or mail.driver).execute_script("window.history.go(-1)") else: print("not an arrow key!")
get() def main_loop(): threading.Thread(target=get_t).start() while(True): device_id, sample_rate, chunk_size, r = stt.setup() with sr.Microphone(device_index = device_id, sample_rate = sample_rate, chunk_size = chunk_size) as source: r.adjust_for_ambient_noise(source) tts.play_plain_text("Hello, What do you want to Do ? Search on Google ? Search on wikipedia ? Send a mail ? ") text = stt.listen(device_id, sample_rate, chunk_size, r, None, source) text = text.lower() text = text.strip() print(text) if "google" in text: google.main.run() elif "stop" in text or "exit" in text : exit(0) break elif "mail" in text or "gmail" in text: mail.run() elif "wiki" in text or "wikipedia" in text: wiki.run() if __name__ == "__main__": main_loop()
import login import main f = open('isLog.txt', "r") to_read = f.read(1024).split(',') if to_read[0] == 'logged in': main.main_loop(to_read[1]) else: login.login()
def test_main_loop(self): mock_callable = MagicMock() main.main_loop(mock_callable, duration=timedelta(seconds=1), nth=100) assert mock_callable.publish.call_count > 1 assert mock_callable.publish.call_count < 100 #cannot send more than 100 messages if we sleep 1/100th
import main main.main_loop()