Spaces:
Sleeping
Sleeping
Eason Lu
commited on
Commit
·
09cabee
1
Parent(s):
ddc27ff
srt class
Browse filesFormer-commit-id: 2716d0ddbf9c22c6921d2874460e1144817f30c2
SRT.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import timedelta
|
| 2 |
+
import os
|
| 3 |
+
import whisper
|
| 4 |
+
|
| 5 |
+
class SRT_segment(object):
|
| 6 |
+
def __init__(self, segment) -> None:
|
| 7 |
+
self.start_time_str = str(0)+str(timedelta(seconds=int(segment['start'])))+',000'
|
| 8 |
+
self.end_time_str = str(0)+str(timedelta(seconds=int(segment['end'])))+',000'
|
| 9 |
+
self.segment_id = segment['id']+1
|
| 10 |
+
self.source_text = segment['text']
|
| 11 |
+
self.duration = f"{self.start_time_str} --> {self.end_time_str}"
|
| 12 |
+
self.translation = ""
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class SRT_script():
|
| 16 |
+
def __init__(self, segments) -> None:
|
| 17 |
+
self.segments = []
|
| 18 |
+
for seg in segments:
|
| 19 |
+
srt_seg = SRT_segment(seg)
|
| 20 |
+
self.segments.append(srt_seg)
|
| 21 |
+
|
| 22 |
+
def get_source_only():
|
| 23 |
+
# return a string
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
def write_srt_file(path:str):
|
| 27 |
+
# write srt file to path
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
|