MCPcopy Create free account
hub / github.com/modelscope/FunClip / Text2SRT

Class Text2SRT

funclip/utils/subtitle_utils.py:29–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 return elements
28
29class Text2SRT():
30 def __init__(self, text, timestamp, offset=0):
31 self.token_list = text
32 self.timestamp = timestamp
33 start, end = timestamp[0][0] - offset, timestamp[-1][1] - offset
34 self.start_sec, self.end_sec = start, end
35 self.start_time = time_convert(start)
36 self.end_time = time_convert(end)
37 def text(self):
38 if isinstance(self.token_list, str):
39 return self.token_list.rstrip("、。,")
40 else:
41 res = ""
42 for word in self.token_list:
43 if '\u4e00' <= word <= '\u9fff':
44 res += word
45 else:
46 res += " " + word
47 return res.lstrip().rstrip("、。,")
48 def srt(self, acc_ost=0.0):
49 return "{} --> {}\n{}\n".format(
50 time_convert(self.start_sec+acc_ost*1000),
51 time_convert(self.end_sec+acc_ost*1000),
52 self.text())
53 def time(self, acc_ost=0.0):
54 return (self.start_sec/1000+acc_ost, self.end_sec/1000+acc_ost)
55
56
57def generate_srt(sentence_list):

Callers 2

generate_srtFunction · 0.85
generate_srt_clipFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected