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
fatal bug fix
维石ed1b49b5999b
diff --git a/funclip/utils/subtitle_utils.py b/funclip/utils/subtitle_utils.pyindex ebcba4b..43a615e 100644--- a/funclip/utils/subtitle_utils.py+++ b/funclip/utils/subtitle_utils.py@@ -45,10 +45,10 @@ class Text2SRT():def generate_srt(sentence_list):srt_total = ''- for i, d in enumerate(sentence_list):- t2s = Text2SRT(d['text'], d['timestamp'])- if 'spk' in d:- srt_total += "{} spk{}\n{}".format(i, d['spk'], t2s.srt())+ for i, sent in enumerate(sentence_list):+ t2s = Text2SRT(sent['text'], sent['timestamp'])+ if 'spk' in sent:+ srt_total += "{} spk{}\n{}".format(i, sent['spk'], t2s.srt())else:srt_total += "{}\n{}".format(i, t2s.srt())return srt_total@@ -58,48 +58,54 @@ def generate_srt_clip(sentence_list, start, end, begin_index=0, time_acc_ost=0.0srt_total = ''cc = 1 + begin_indexsubs = []- for i, d in enumerate(sentence_list):- if d['timestamp'][-1][1] <= start:+ for _, sent in enumerate(sentence_list):+ if sent['timestamp'][-1][1] <= start:+ print("CASE0")continue- if d['timestamp'][0][0] >= end:+ if sent['timestamp'][0][0] >= end:+ print("CASE4")break# parts in between- if (d['timestamp'][-1][1] <= end and d['timestamp'][0][0] > start) or (d['timestamp'][-1][1] == end and d['timestamp'][0][0] == start):- t2s = Text2SRT(d['text'], d['timestamp'], offset=start)+ if (sent['timestamp'][-1][1] <= end and sent['timestamp'][0][0] > start) or (sent['timestamp'][-1][1] == end and sent['timestamp'][0][0] == start):+ print("CASE1")+ t2s = Text2SRT(sent['text'], sent['timestamp'], offset=start)srt_total += "{}\n{}".format(cc, t2s.srt(time_acc_ost))subs.append((t2s.time(time_acc_ost), t2s.text()))cc += 1continue- if d['timestamp'][0][0] <= start:- if not d['timestamp'][-1][1] > end:- for j, ts in enumerate(d['timestamp']):+ if sent['timestamp'][0][0] <= start:+ print("CASE2")+ if not sent['timestamp'][-1][1] > end:+ for j, ts in enumerate(sent['timestamp']):if ts[1] > start:break- _text = " ".join(d['text'].split()[j:])- _ts = d['timestamp'][j:]+ _text = " ".join(sent['text'][j:])+ _ts = sent['timestamp'][j:]else:- for j, ts in enumerate(d['timestamp']):+ for j, ts in enumerate(sent['timestamp']):if ts[1] > start:_start = jbreak- for j, ts in enumerate(d['timestamp']):+ for j, ts in enumerate(sent['timestamp']):if ts[1] > end:_end = jbreak- _text = " ".join(d['text'].split()[_start:_end])- _ts = d['timestamp'][_start:_end]+ _text = " ".join(sent['text'][_start:_end])+ _ts = sent['timestamp'][_start:_end]if len(ts):t2s = Text2SRT(_text, _ts, offset=start)srt_total += "{}\n{}".format(cc, t2s.srt(time_acc_ost))subs.append((t2s.time(time_acc_ost), t2s.text()))cc += 1+ # import pdb; pdb.set_trace()continue- if d['timestamp'][-1][1] > end:- for j, ts in enumerate(d['timestamp']):+ if sent['timestamp'][-1][1] > end:+ print("CASE3")+ for j, ts in enumerate(sent['timestamp']):if ts[1] > end:break- _text = " ".join(d['text'].split()[:j])- _ts = d['timestamp'][:j]+ _text = " ".join(sent['text'][:j])+ _ts = sent['timestamp'][:j]if len(_ts):t2s = Text2SRT(_text, _ts, offset=start)srt_total += "{}\n{}".format(cc, t2s.srt(time_acc_ost))diff --git a/funclip/videoclipper.py b/funclip/videoclipper.pyindex cdbcae3..9d8e4d9 100644--- a/funclip/videoclipper.py+++ b/funclip/videoclipper.py@@ -121,6 +121,7 @@ class VideoClipper():video = mpy.VideoFileClip(video_filename)# Extract the base name, add '_clip.mp4', and 'wav'if output_dir is not None:+ os.makedirs(output_dir, exist_ok=True)_, base_name = os.path.split(video_filename)base_name, _ = os.path.splitext(base_name)clip_video_file = base_name + '_clip.mp4'@@ -233,7 +234,7 @@ class VideoClipper():clip_video_file_name, _ = os.path.splitext(file_with_extension)print(output_dir, clip_video_file)clip_video_file = os.path.join(output_dir, "{}_no{}.mp4".format(clip_video_file_name, self.GLOBAL_COUNT))- temp_audio_file = os.path.join(output_dir, "{}_no{}.mp3".format(clip_video_file_name, self.GLOBAL_COUNT))+ temp_audio_file = os.path.join(output_dir, "{}_tempaudio_no{}.mp4".format(clip_video_file_name, self.GLOBAL_COUNT))else:clip_video_file = clip_video_file[:-4] + '_no{}.mp4'.format(self.GLOBAL_COUNT)temp_audio_file = clip_video_file[:-4] + '_tempaudio_no{}.mp4'.format(self.GLOBAL_COUNT)