-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio2text.py
32 lines (23 loc) · 1007 Bytes
/
audio2text.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
import speech_recognition as sr
class Recognizer:
def __init__(self, ):
# Initialize recognizer class (for recognizing the speech)
self.r = sr.Recognizer()
def transcribe(self, path, lang='en-IN'):
# Reading Audio file as source
# listening the audio file and store in audio_text variable
with sr.AudioFile(path) as source:
audio_text = self.r.listen(source)
# recoginize_() method will throw a request error if the API is unreachable, hence using exception handling
try:
# using google speech recognition
text = self.r.recognize_google(audio_text, language = lang)
print('Converting audio transcripts into text ...')
print(text)
except:
print('Sorry.. run again...')
def main():
recognizer = Recognizer()
recognizer.transcribe("test_malayalam.wav", lang='ml-IN')
if __name__ == "__main__":
main()