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.shi9b838f828e6d
diff --git a/ClipVideo/clipvideo/gradio_service.py b/ClipVideo/clipvideo/gradio_service.pyindex 0cb8e06..84cba0b 100644--- a/ClipVideo/clipvideo/gradio_service.py+++ b/ClipVideo/clipvideo/gradio_service.py@@ -81,7 +81,11 @@ if __name__ == "__main__":'https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/2022%E4%BA%91%E6%A0%96%E5%A4%A7%E4%BC%9A_%E7%89%87%E6%AE%B5.mp4','https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/2022%E4%BA%91%E6%A0%96%E5%A4%A7%E4%BC%9A_%E7%89%87%E6%AE%B52.mp4','https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E4%BD%BF%E7%94%A8chatgpt_%E7%89%87%E6%AE%B5.mp4'],- [video_input])+ [video_input],+ label='语音识别示例 ASR Demo')+ gr.Examples(['https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E8%AE%BF%E8%B0%88.mp4'],+ [video_input],+ label='说话人切分示例 SD Demo')video_sd_switch = gr.Radio(["no", "yes"], label="👥是否区分说话人 Recognize Speakers", value='no')recog_button2 = gr.Button("👂识别 Recognize")video_text_output = gr.Textbox(label="✏️识别结果 Recognition Result")@@ -117,7 +121,7 @@ if __name__ == "__main__":audio_spk_input = gr.Textbox(label="✏️待裁剪说话人 Speaker to Clip (多个说话人使用'#'连接)")with gr.Row():audio_start_ost = gr.Slider(minimum=-500, maximum=1000, value=0, step=50, label="⏪开始位置偏移 Start Offset (ms)")- audio_end_ost = gr.Slider(minimum=-500, maximum=1000, value=100, step=50, label="⏩结束位置偏移 End Offset (ms)")+ audio_end_ost = gr.Slider(minimum=-500, maximum=1000, value=0, step=50, label="⏩结束位置偏移 End Offset (ms)")with gr.Row():clip_button1 = gr.Button("✂️裁剪 Clip")audio_output = gr.Audio(label="🔊裁剪结果 Audio Clipped")diff --git a/ClipVideo/clipvideo/videoclipper.py b/ClipVideo/clipvideo/videoclipper.pyindex a649076..66cc79c 100644--- a/ClipVideo/clipvideo/videoclipper.py+++ b/ClipVideo/clipvideo/videoclipper.py@@ -67,7 +67,7 @@ class VideoClipper():ts = proc_spk(_dest_spk, state['sd_sentences'])for _ts in ts: all_ts.append(_ts)ts = all_ts- ts.sort()+ # ts.sort()srt_index = 0clip_srt = ""if len(ts):@@ -130,7 +130,7 @@ class VideoClipper():for _ts in ts: all_ts.append(_ts)time_acc_ost = 0.0ts = all_ts- ts.sort()+ # ts.sort()clip_srt = ""if len(ts):start, end = ts[0][0] / 16000, ts[0][1] / 16000@@ -148,14 +148,19 @@ class VideoClipper():for _ts in ts[1:]:start, end = _ts[0] / 16000, _ts[1] / 16000srt_clip, subs, srt_index = generate_srt_clip(sentences, start, end, begin_index=srt_index-1, time_acc_ost=time_acc_ost)+ chi_subs = []+ sub_starts = subs[0][0][0]+ for sub in subs:+ chi_subs.append(((sub[0][0]-sub_starts, sub[0][1]-sub_starts), sub[1]))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)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)+ subtitles = SubtitlesClip(chi_subs, generator)_video_clip = CompositeVideoClip([_video_clip, subtitles.set_pos(('center','bottom'))])+ # _video_clip.write_videofile("debug.mp4", audio_codec="aac")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_info