Skip to content

Commit a557ad5

Browse files
authored
Create speech_recognizer.py
1 parent d3c3590 commit a557ad5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pyttsx3
2+
import speech_recognition as sr
3+
4+
5+
engine = pyttsx3.init()
6+
7+
8+
def fun_talk(audio):
9+
engine.say(audio)
10+
engine.runAndWait()
11+
12+
13+
def get_command():
14+
15+
rec = sr.Recognizer()
16+
with sr.Microphone() as source:
17+
print("Say something...")
18+
rec.pause_threshold = 1
19+
20+
audio = rec.listen(source)
21+
22+
try:
23+
print("Recognizing...")
24+
command = rec.recognize_google(audio, language='en-in')
25+
print(f"You said: {command}\n")
26+
fun_talk(f"You said: {command}\n")
27+
28+
except Exception as e:
29+
# print(e)
30+
print("Say that again please...")
31+
return "None"
32+
33+
return command
34+
35+
36+
if __name__ == '__main__':
37+
38+
if 1:
39+
40+
query = get_command().lower()

0 commit comments

Comments
 (0)