-
Notifications
You must be signed in to change notification settings - Fork 0
/
align.py
57 lines (38 loc) · 1.5 KB
/
align.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from process import inbox , clip , string_to_txt, json_to_csv, outbox, check, cleaning
import os
import argparse
import requests
import json
parser = argparse.ArgumentParser(description='Align your subtitles in a movie by use of Deep learning library Align. Get a srt file in output using commands listed bellow!')
parser.add_argument('-m', type=str, help='movie file name' , required=True)
parser.add_argument('-s', type=str, help='subtitles file name' , required=True)
parser.add_argument('-o', type=str, help='output srt file', default = 'new subtitles.srt')
if __name__ == "__main__":
args = parser.parse_args()
srt = args.s
movie = args.m
out = args.o
cut = "cut.mkv"
audio = "audio.mp3"
text , data = inbox(srt)
last = data[-1][0]
clip(last, movie, cut, audio)
string_to_txt(text)
print('gentle Docker API -- install by `~$ sudo docker run -P lowerquality/gentle` ')
params = (
('async', 'false'),
)
files = {
'audio': ('text.mp3', open(audio, 'rb')),
'transcript': ('text.txt', open('out.txt', 'rb')),
}
r = requests.post('http://localhost:32768/transcriptions', params=params, files=files)
r = r.json()
with open('out.json', 'w') as f:
json.dump(r, f)
# os.system("curl -X POST -F 'audio=@{}' -F 'transcript=<{}' 'http://gentle-demo.lowerquality.com/transcriptions?async=false' -o {}".format(audio, "out.txt", "out.json"))
json_to_csv("out.json")
delay = check(out = "out.csv", data = data)
print('time delay:', delay)
outbox(srt, new = out, delay = delay)
cleaning()