forked from prathimacode-hub/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeech_recognizer.py
43 lines (31 loc) · 1.05 KB
/
speech_recognizer.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
# pip install SpeechRecognition
import speech_recognition as sr
# pip install pyttsx3
import pyttsx3
# creating object
engine = pyttsx3.init()
# function for speaking up the recognized voice through speakers
def fun_talk(audio):
engine.say(audio)
engine.runAndWait()
# function for taking the voice commands and recognizing it
def get_command():
rec = sr.Recognizer()
with sr.Microphone() as source:
print("Say something...")
rec.pause_threshold = 1
audio = rec.listen(source)
try:
print("Recognizing...")
command = rec.recognize_google(audio, language='en-in')
print(f"You said: {command}\n")
fun_talk(f"You said: {command}\n")
except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return command
if __name__ == '__main__':
if 1:
# taking the input as voice command from the user
query = get_command().lower()