-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtranscribe.py
31 lines (21 loc) · 950 Bytes
/
transcribe.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
import argparse
from pathlib import Path
import whisper
from whisper.utils import WriteSRT
modelSize = "large"
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Synchronize SRT timestamps over an existing accurate transcription.")
parser.add_argument('pathMp3', type=str, help="Path to the SRT file with good timestamps")
parser.add_argument('modelSize', type=str, help="Path to the TXT file with good text", nargs='?')
args = parser.parse_args()
if args.modelSize != None:
modelSize = args.modelSize
print("Loading Whisper model: "+modelSize+" ...")
model = whisper.load_model(modelSize)
print("Transcribing: "+args.pathMp3+" ...")
result = model.transcribe(args.pathMp3)
print(result["text"])
print("Saving: "+args.pathMp3+".srt ...")
p = Path(args.pathMp3)
writer = WriteSRT(p.parent)
writer(result, args.pathMp3)