-
Notifications
You must be signed in to change notification settings - Fork 0
/
speech_interface.py
67 lines (54 loc) · 2.74 KB
/
speech_interface.py
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
import speech_recognition as sr
import subprocess
import os
import pyttsx3
def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
def run_program_in_different_directory(program_path, directory_path):
os.chdir(directory_path)
try:
subprocess.run(['python', program_path], check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
finally:
os.chdir(os.path.dirname(os.path.realpath(__file__)))
def main():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
while True:
speak("Listening for a command")
print("Listening for a command...")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio).lower()
print("You said:", command)
if "quit" in command:
speak("Exiting the program.")
break
if "run" in command:
file_name = command.replace("run", "").strip()
if file_name == "hand gesture":
program_path = r"C:\Users\vaibhav\Desktop\PES Super File\cRAIS\hand_gesture_recognition_working\hand_gesture_detection.py"
directory_path = r"C:\Users\vaibhav\Desktop\PES Super File\cRAIS\hand_gesture_recognition_working"
run_program_in_different_directory(program_path, directory_path)
if file_name == "emotion recognition":
program_path = r"C:\Users\vaibhav\Desktop\PES Super File\cRAIS\emotion_recognition\emotion_recognition.py"
directory_path = r"C:\Users\vaibhav\Desktop\PES Super File\cRAIS\emotion_recognition"
run_program_in_different_directory(program_path, directory_path)
if file_name == "text recognition":
program_path = r"C:\Users\vaibhav\Desktop\PES Super File\cRAIS\text_recognition\ocr_for_cam.py"
directory_path = r"C:\Users\vaibhav\Desktop\PES Super File\cRAIS\text_recognition"
run_program_in_different_directory(program_path, directory_path)
else:
print("Sorry, I couldn't understand the command.")
speak("Sorry, I couldn't understand the command.")
except sr.UnknownValueError:
print("Sorry, I couldn't understand the speech.")
speak("Sorry, I couldn't understand the speech.")
except sr.RequestError as e:
print(f"Error with the speech recognition service: {e}")
if __name__ == "__main__":
main()