-
Notifications
You must be signed in to change notification settings - Fork 0
/
S2T.py
49 lines (40 loc) · 1.57 KB
/
S2T.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
import speech_recognition as SRG
import requests
store = SRG.Recognizer()
import time
def startListening(timesec):
time.sleep(int(timesec))
with SRG.Microphone() as s:
text_output=""
print("Speak...")
nameCall=""
store.adjust_for_ambient_noise(s)
audio_input = store.record(s, duration=3)
try:
nameCall = store.recognize_google(audio_input)
print(nameCall)
if nameCall.lower()== "jessica":
print("word found")
with SRG.Microphone() as s:
store.adjust_for_ambient_noise(s)
audio_input = store.record(s, duration=5)
text_output = store.recognize_google(audio_input)
text_output=text_output.lower()
if(len(text_output)>1):
r = requests.post('http://localhost:8080/crisper/v1/exec',json={'command':text_output})
print(r.text)
print("Text converted from audio:\n")
print(text_output)
text_output=""
print("Finished!!")
print("Execution time:",time.strftime("%I:%M:%S"))
except:
print("Couldn't process the audio input.")
text_output=text_output.lower()
if(len(text_output)>1):
r = requests.post('http://localhost:8080/crisper/v1/exec',json={'command':text_output})
print(r.text)
while True:
startListening(0)
#thread=threading.Thread(target=startListening, args=(1,))
#thread.start()