-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_api.py
More file actions
36 lines (31 loc) · 1.29 KB
/
run_api.py
File metadata and controls
36 lines (31 loc) · 1.29 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
import argparse
from Transcriber import Transcriber
from glob import glob
parser = argparse.ArgumentParser(description="Transcribe YouTube Videos Using Whisper API from OpenAI",
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-link", type=str,
help="link to YouTube video")
parser.add_argument("-gdrive", type=str, default=None,
help="path to google drive video")
parser.add_argument("-name", type=str,
help="name of the output")
parser.add_argument("-apikey", type=str, default=False,
help="OpenAI API key")
def console_entry():
args = parser.parse_args()
# Initialize transcriber
transcriber = Transcriber(openai_key=args.apikey, model_size=None)
# Download and save audio file
if args.gdrive:
transcriber.extract_audio_gdrive(args.gdrive)
else:
transcriber.download_audio(args.link)
# Start transcribing
for ind, audio_file in enumerate(sorted(glob("./Data/Chunks/*.m4a"))):
result = transcriber.transcribe_api(audio_file)
transcriber.write_api_result(result, args.name, ind)
print("Transcribe completed!!")
# Clear download folders
transcriber.clear()
if __name__ == '__main__':
console_entry()