-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (31 loc) · 996 Bytes
/
Copy pathmain.py
File metadata and controls
52 lines (31 loc) · 996 Bytes
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
import whisper
def convert_time_stamp(time):
hr=int(time/3600)
min=int((time/60)-hr*60)
sec=int(time-hr*3600-min*60)
ms=int((time*100)%100)
return(('%02d' % hr)+':'+('%02d' % min)+':'+('%02d' % sec)+','+('%03d' % ms))
def generate_subtitles(input_audio,output_path,Model="small"):
model = whisper.load_model(Model)
result = model.transcribe(input_audio,word_timestamps=True)
fp = open(output_path, "w")
seq=0
for line in result["segments"]:
print(line)
srt=""
seq+=1
time=convert_time_stamp(line['start'])
srt+=(str(seq)+'\n'+time+' --> ')
if(line['text'].len()>80):
pass
time=convert_time_stamp(line['end'])
srt+=(time+'\n')
srt+=(line['text']+'\n\n')
fp.write(srt)
fp.close()
generate_subtitles(input_audio="tmp/english.mp3",output_path="tmp/subtitl2.srt")
'''
Todo:
Break large sentences into small segments
UI for easy use
'''