forked from lazyfay/Python-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpeechRecognition.py
More file actions
37 lines (36 loc) · 1.05 KB
/
Copy pathSpeechRecognition.py
File metadata and controls
37 lines (36 loc) · 1.05 KB
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
import speech_recognition as sr
import datetime
def recog():
reco = sr.Recognizer()
with sr.Microphone() as source:
print("speak...")
reco.pause_threshold = 1
audio = reco.listen(source)
try:
output = reco.recognize_google(audio , language='en-in')
output = str(output)
except sr.UnKnownValueError:
print("did not understand")
return recog()
return output
def file(speech):
day = datetime.datetime.now().day
time_hour = datetime.datetime.now().hour
time_min = datetime.datetime.now().minute
file_name = "day " + str(day) + "_" + "time "+ str(time_hour) + "_" + str(time_min)
file_name = ("notepad/" + file_name + ".txt")
f = open(file_name , "a")
f.write(speech)
f.close()
print("saved in " + file_name)
##MAIN START##
def main():
speech = recog()
print("You said :\n" + speech)
flag = input("Do you want to save this into a file\n")
flag.lower()
if flag == "yes":
file(speech)
else:
main()
main()