-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeechRecognition.py
More file actions
47 lines (40 loc) · 1.27 KB
/
speechRecognition.py
File metadata and controls
47 lines (40 loc) · 1.27 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
38
39
40
41
42
43
44
45
46
47
import speech_recognition as sr
from os import path
import os
from video import *
def speech_recognition(ID,info):
r = sr.Recognizer()
with sr.Microphone() as source:
print("USER SAY: ")
audio = r.listen(source)
if path.exists("users\\{}".format(ID)):
with open("users\\{}\\{} {}.wav".format(ID,ID,info), "wb") as f:
f.write(audio.get_wav_data())
else:
try:
os.makedirs("users\\{}".format(ID))
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)
try:
with open("users\\{}\\{} {}.wav".format(ID,ID,info), "wb") as f:
f.write(audio.get_wav_data())
text = r.recognize_google(audio)
print("{}".format(text))
except:
print("the sample do not recognized")
return ""
return text
def speech_recognitionID():
r = sr.Recognizer()
with sr.Microphone() as source:
print("USER SAY: ")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("{}".format(text))
except:
print("the sample do not recognized")
return ""
return text