-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisten.py
43 lines (36 loc) · 1.13 KB
/
listen.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
import speech_recognition as sr
from recognize_speech import recognize_speech
from write import writeS
def file(fname, path):
recognizer = sr.Recognizer()
microphone = sr.Microphone()
try:
speech = recognize_speech(sr, recognizer, microphone, fname)
return writeS(speech, path)
except FileNotFoundError:
return 'file {} does not exist'.format(fname)
def mic(path):
recognizer = sr.Recognizer()
microphone = sr.Microphone()
speech = ''
while True:
try:
phrase = recognize_speech(sr, recognizer, microphone)
if phrase:
speech += phrase + ' '
print(phrase)
except KeyboardInterrupt:
if speech:
writeS(speech, path)
break
if __name__ == '__main__':
while True:
inp = input('f or m: ')
if inp == 'f':
file(input('file name: '), "./summmaries/f.txt")
elif inp == 'm':
mic("./summmaries/mic.txt")
else:
print('invalid')
# to import from elsewhere, import filename
# then run function file(fname) or mic()