-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathengine.py
More file actions
36 lines (30 loc) · 955 Bytes
/
engine.py
File metadata and controls
36 lines (30 loc) · 955 Bytes
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
import pyttsx3
import speech_recognition as sr
from playsound import playsound
def speak(audio):
# the speak feature thing.
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[0].id)
engine.say(audio)
engine.runAndWait()
def takeCommand():
# It takes microphone input from the user and returns string output
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
playsound('UI/sounds/istart.mp3')
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
playsound('UI/sounds/istop.mp3')
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
# print(e)
print("didn't get that!")
return "None"
return query