FunASR-powered video transcription, subtitle generation, and LLM-assisted clipping tool with a local Gradio UI.
Python ai-toolsai-video-editingasrauto-subtitleschinesecontent-creationfunasrfunclipgradiollmparaformerspeech-recognitionspeech-to-textsubtitles-generatortranscriptionvideo-editingvideo-processingvideo-subtitlesvideo-transcriptionwhisper-alternative
bug fix
shixian.shiba348b0fc197
diff --git a/ClipVideo/clipvideo/subtitle_utils.py b/ClipVideo/clipvideo/subtitle_utils.pyindex a3d9a47..797a0dd 100644--- a/ClipVideo/clipvideo/subtitle_utils.py+++ b/ClipVideo/clipvideo/subtitle_utils.py@@ -34,10 +34,13 @@ class Text2SRT():return resdef len(self):return len(self.token_list)- def srt(self):- return "{} --> {}\n{}\n".format(self.start_time, self.end_time, self.text())- def time(self):- return (self.start_sec/1000, self.end_sec/1000)+ def srt(self, acc_ost=0.0):+ return "{} --> {}\n{}\n".format(+ time_convert(self.start_sec+acc_ost*1000),+ time_convert(self.end_sec+acc_ost*1000),+ self.text())+ def time(self, acc_ost=0.0):+ return (self.start_sec/1000+acc_ost, self.end_sec/1000+acc_ost)def generate_srt(sentence_list):@@ -47,7 +50,7 @@ def generate_srt(sentence_list):srt_total += "{}\n{}".format(i, t2s.srt())return srt_total-def generate_srt_clip(sentence_list, start, end, begin_index=0):+def generate_srt_clip(sentence_list, start, end, begin_index=0, time_acc_ost=0.0):start, end = int(start * 1000), int(end * 1000)srt_total = ''cc = 1 + begin_index@@ -58,10 +61,10 @@ def generate_srt_clip(sentence_list, start, end, begin_index=0):if d['ts_list'][0][0] >= end:break# parts in between- if (d['ts_list'][-1][1] < end and d['ts_list'][0][0] > start) or (d['ts_list'][-1][1] == end and d['ts_list'][0][0] == start):+ if (d['ts_list'][-1][1] <= end and d['ts_list'][0][0] > start) or (d['ts_list'][-1][1] == end and d['ts_list'][0][0] == start):t2s = Text2SRT(d['text_seg'], d['ts_list'], offset=start)- srt_total += "{}\n{}".format(cc, t2s.srt())- subs.append((t2s.time(), t2s.text()))+ srt_total += "{}\n{}".format(cc, t2s.srt(time_acc_ost))+ subs.append((t2s.time(time_acc_ost), t2s.text()))cc += 1continueif d['ts_list'][0][0] <= start:@@ -84,8 +87,8 @@ def generate_srt_clip(sentence_list, start, end, begin_index=0):_ts = d['ts_list'][_start:_end]if len(ts):t2s = Text2SRT(_text, _ts, offset=start)- srt_total += "{}\n{}".format(cc, t2s.srt())- subs.append((t2s.time(), t2s.text()))+ srt_total += "{}\n{}".format(cc, t2s.srt(time_acc_ost))+ subs.append((t2s.time(time_acc_ost), t2s.text()))cc += 1continueif d['ts_list'][-1][1] > end:@@ -96,9 +99,9 @@ def generate_srt_clip(sentence_list, start, end, begin_index=0):_ts = d['ts_list'][:j]if len(_ts):t2s = Text2SRT(_text, _ts, offset=start)- srt_total += "{}\n{}".format(cc, t2s.srt())+ srt_total += "{}\n{}".format(cc, t2s.srt(time_acc_ost))subs.append(- (t2s.time(), t2s.text())+ (t2s.time(time_acc_ost), t2s.text()))cc += 1continuediff --git a/ClipVideo/clipvideo/videoclipper.py b/ClipVideo/clipvideo/videoclipper.pyindex 491bc45..6d50f9d 100644--- a/ClipVideo/clipvideo/videoclipper.py+++ b/ClipVideo/clipvideo/videoclipper.py@@ -105,36 +105,40 @@ class VideoClipper():all_ts = []srt_index = 0+ time_acc_ost = 0.0for _dest_text in dest_text.split('#'):_dest_text = pre_proc(_dest_text)ts = proc(recog_res_raw, timestamp, _dest_text)for _ts in ts: all_ts.append(_ts)+ import pdb; pdb.set_trace()ts = all_tsclip_srt = ""if len(ts):start, end = ts[0][0] / 16000, ts[0][1] / 16000+ srt_clip, subs, srt_index = generate_srt_clip(sentences, start, end, begin_index=srt_index, time_acc_ost=time_acc_ost)start, end = start+start_ost/1000.0, end+end_ost/1000.0video_clip = video.subclip(start, end)start_end_info = "from {} to {}".format(start, end)- srt_clip, subs, srt_index = generate_srt_clip(sentences, start, end, begin_index=srt_index)clip_srt += srt_clipif add_sub:generator = lambda txt: TextClip(txt, font='./font/STHeitiMedium.ttc', fontsize=font_size, color=font_color)subtitles = SubtitlesClip(subs, generator)video_clip = CompositeVideoClip([video_clip, subtitles.set_pos(('center','bottom'))])concate_clip = [video_clip]+ time_acc_ost += end+end_ost/1000.0 - (start+start_ost/1000.0)for _ts in ts[1:]:start, end = _ts[0] / 16000, _ts[1] / 16000+ srt_clip, subs, srt_index = generate_srt_clip(sentences, start, end, begin_index=srt_index-1, time_acc_ost=time_acc_ost)start, end = start+start_ost/1000.0, end+end_ost/1000.0_video_clip = video.subclip(start, end)start_end_info += ", from {} to {}".format(start, end)- srt_clip, subs, srt_index = generate_srt_clip(sentences, start, end, begin_index=srt_index-1)clip_srt += srt_clipif add_sub:generator = lambda txt: TextClip(txt, font='./font/STHeitiMedium.ttc', fontsize=font_size, color=font_color)subtitles = SubtitlesClip(subs, generator)_video_clip = CompositeVideoClip([_video_clip, subtitles.set_pos(('center','bottom'))])concate_clip.append(copy.copy(_video_clip))+ time_acc_ost += end+end_ost/1000.0 - (start+start_ost/1000.0)message = "{} periods found in the audio: ".format(len(ts)) + start_end_infologging.warning("Concating...")if len(concate_clip) > 1: