forked from MrBents/senior_design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_speech.py
48 lines (36 loc) · 1.37 KB
/
google_speech.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
import speech_recognition as sr
import Audio
import multiprocessing
class adios:
def __init__(self):
self.rek = sr.Recognizer()
self.audio = ""
#self.pool = multiprocessing.Pool(1)
# self.pool.apply_async(self.record())
def record(self):
#pool = multiprocessing.Pool(1)
with sr.Microphone() as source:
print('say Something')
try:
# p = multiprocessing.Process(target=self.rek.listen, args=(source,))
#res = pool.apply_async(self.rek.listen, [source])
self.audio = self.rek.listen(source,timeout=0, phrase_time_limit=5)
# p.start()
# p.join()
except Exception as e:
print('something timed out, ' + str(e))
#print('audio recorded')
# write audio to a WAV file
#with open("Recording1.wav", "wb") as f:
#f.write(self.audio.get_wav_data())
#f.close()
def get_adios(self):
# print('Google transcribe:')
# print('{}'.format(self.rek.recognize_google(self.audio)))
return (self.rek.recognize_google(self.audio,language = 'en-EN'))
if __name__ == "__main__":
adddd = Audio.Audio()
aids = adios()
aids.record()
a = adddd.getOrder(aids.get_adios())
print(a)