-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_transcript.py
34 lines (24 loc) · 1022 Bytes
/
generate_transcript.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
import speech_recognition as sr
import argparse
import os
def generate_transcript(filename):
r = sr.Recognizer()
with sr.AudioFile(filename) as source:
audio = r.record(source)
transcript = r.recognize_google(audio)
return transcript
def save_transcript(transcript, file_name):
with open(file_name, 'w') as f:
f.write(transcript)
def main():
parser = argparse.ArgumentParser(description='Generate Transcript from Video')
parser.add_argument('filename', metavar='filename', type=str, help='The path to the video file')
parser.add_argument('--output', metavar='output', type=str, help='The path to save the transcript file', default=None)
args = parser.parse_args()
transcript = generate_transcript(args.filename)
print(transcript)
if args.output is not None:
save_transcript(transcript, args.output)
print(f'Successfully generated transcript and saved it to {os.path.abspath(args.output)}')
if __name__ == '__main__':
main()