Commit c1e2b998 authored by LiniEisha's avatar LiniEisha

Reformatting speech_to_text.py

parent 82b58cef
...@@ -4,17 +4,17 @@ import os ...@@ -4,17 +4,17 @@ import os
def speech_to_text(video_name): def speech_to_text(video_name):
#calling the Recognizer()
r = sr.Recognizer() r = sr.Recognizer()
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(os.path.abspath(__file__))
VIDEO_PATH = os.path.join(BASE_DIR, "lectures\\{}".format(video_name)) VIDEO_PATH = os.path.join(BASE_DIR, "lectures\\{}".format(video_name))
with sr.AudioFile(VIDEO_PATH) as source: with sr.AudioFile(VIDEO_PATH) as source:
audio = r.listen(source) audio = r.listen(source)
file = open('audioToText01.txt', 'w') file = open('audioToText01.txt', 'w') #open file
try: try:
text = r.recognize_google(audio) text = r.recognize_google(audio) #Convert using google recognizer
file.write(text) file.write(text)
except: except:
file.write('error') file.write('error')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment