From 147807de21e927f8c17478916b039c01c2c24d7a Mon Sep 17 00:00:00 2001 From: Sristi Date: Thu, 11 Nov 2021 18:01:59 +0530 Subject: [PATCH] Revert "Fixed the v_assistant feature." This reverts commit 7146c650ab3d570bd9bf3cd58c3b0a719b9f3480. --- virtual_doodle/Navigation.py | 4 +- virtual_doodle/speech.py | 98 ++++++++++++++++++++++++++---------- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/virtual_doodle/Navigation.py b/virtual_doodle/Navigation.py index 3217c10..20ce2cf 100644 --- a/virtual_doodle/Navigation.py +++ b/virtual_doodle/Navigation.py @@ -18,9 +18,9 @@ def hover_and_click(status, click, x, y): def standard_scroll(key='down'): if key == 'down': - pyautogui.scroll(-30) + pyautogui.scroll(-20) else: - pyautogui.scroll(30) + pyautogui.scroll(20) diff --git a/virtual_doodle/speech.py b/virtual_doodle/speech.py index aaf0bfa..496fefd 100644 --- a/virtual_doodle/speech.py +++ b/virtual_doodle/speech.py @@ -25,50 +25,96 @@ def phone_number(r, source): return phone -def initialize_project(init=True): +def initialize_project(count = 0): import speech_recognition as sr import os import pyttsx3 + r = sr.Recognizer() engine = pyttsx3.init() - if init: - msg = "Welcome to Touch Me Not. What would you like to explore? Virtual Doodle, Classroom or Self Checkout? " - speak(msg) - init = False + + + + try: with sr.Microphone() as source: + speak("How may I help you?") + # read the audio data from the default microphone audio_data = r.record(source, duration=2) - command = r.recognize_google(audio_data) - if "".join(command.lower().split()) == "virtualdoodle": - msg = "Virtual Doodle has been activated." - speak(msg) - return "lvdl" - elif "".join(command.lower().split()) == "classroom": - msg = "Virtual Classroom has been activated." + print("Recognizing...") + # convert speech to text + text = r.recognize_google(audio_data) + if "".join(text.lower().split()) == "touchmenot" and count == 0: + count += 1 + + msg = "Welcome to Touch Me Not. Please choose the option you would like to proceed on: " speak(msg) - return "cls" - elif "".join(command.lower().split()) == "checkout": - phone = phone_number(r, source) - confirm_data = r.record(source, duration=2) - confirm = r.recognize_google(confirm_data) - print(confirm) - if "".join(confirm.lower().split()) == "yes": - return "chk", phone + audio_data = r.record(source, duration=2) + command = r.recognize_google(audio_data) + if "".join(command.lower().split()) == "virtualdoodle": + msg = "Virtual Doodle has been activated." + speak(msg) + return "lvdl" + elif "".join(command.lower().split()) == "classroom": + msg = "Virtual Classroom has been activated." + speak(msg) + return "cls" + elif "".join(command.lower().split()) == "checkout": + phone = phone_number(r, source) + confirm_data = r.record(source, duration=2) + confirm = r.recognize_google(confirm_data) + print(confirm) + if "".join(confirm.lower().split()) == "yes": + return "chk", phone + else: + phone = phone_number(r, source) else: + msg = "I am sorry but " + command + \ + " is not a valid command. Please say Touch Me Not to proceed again. If you wish to exit, please say Exit." + speak(msg) + return initialize_project(count) + if( "".join(text.lower().split()) == "touchmenot" and count > 0): + msg = " Please choose the option you would like to proceed on: " + speak(msg) + audio_data = r.record(source, duration=2) + command = r.recognize_google(audio_data) + if "".join(command.lower().split()) == "virtualdoodle": + msg = "Virtual Doodle has been activated." + speak(msg) + return "lvdl" + elif "".join(command.lower().split()) == "classroom": + msg = "Virtual Classroom has been activated." + speak(msg) + return "cls" + elif "".join(command.lower().split()) == "checkout": phone = phone_number(r, source) - elif "".join(command.lower().split()) == "exit": + confirm_data = r.record(source, duration=2) + confirm = r.recognize_google(confirm_data) + print(confirm) + if "".join(confirm.lower().split()) == "yes": + return "chk", phone + else: + phone = phone_number(r, source) + else: + msg = "I am sorry but " + command + \ + " is not a valid command. Please say Touch Me Not to proceed again. If you wish to exit, please say Exit." + speak(msg) + return initialize_project(count) + + elif "".join(text.lower().split()) == "exit": msg = "Bye. See you later." speak(msg) + return None else: - msg = "I am sorry but " + command + \ - " is not a valid command. If you wish to exit, please say Exit." + msg = "I am sorry but " + text + \ + " is not a valid command. Please say Touch Me Not to proceed again. If you wish to exit, please say Exit." speak(msg) - return initialize_project(init) + return initialize_project(count) except: - msg = "I am sorry I didn't get that. If you wish to exit, please say Exit." + msg = "I am sory I didn't get that. Please say Touch Me Not to proceed again. If you wish to exit, please say Exit." speak(msg) - return initialize_project(init) + return initialize_project(count) def launch_project(url):