-
Notifications
You must be signed in to change notification settings - Fork 1
/
s2t2.py
38 lines (34 loc) · 1.24 KB
/
s2t2.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
!#/usr/bin/env_python3
import speech_recognition as sr
import os,time
# microphone detection
class CustomSource(sr.Microphone):
def init(self, device_index = None, sample_rate = 16000, chunk_size = 1024):
print("about to initialize microphone")
result = super(self.__class__, self).init()
print("done initializing microphone")
return result
#calling speech recognizer's function
class CustomRecognizer(sr.Recognizer):
def listen(self, source, timeout = 10):
print("speak a valid command \n !!Caution expert pronunciation Required ")
print("starting listening")
result = super(self.__class__, self).listen(source, timeout)
print("done listening")
return result
try:
#time.sleep(2)
#print(" ")
#print(" ")
sr.Recognizer = CustomRecognizer
sr.Microphone = CustomSource
r = sr.Recognizer()
with sr.Microphone(chunk_size = 512) as source:
audio = r.listen(source)
user_input_command = r.recognize_google(audio)
print (user_input_command)
x=os.system(user_input_command)
print (x)
#print("you said: " + r.recognize_google(audio))
except:
os.system('echo " this is not a command,try again" | festival --tts')