Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,23 @@ ImageMagick is only needed for the legacy demo or a custom MoviePy 1.x `TextClip
## Use FunClip

### A. Use FunClip as local Gradio Service
You can establish your own FunClip service which is same as [Modelscope Space](https://modelscope.cn/studios/iic/funasr_app_clipvideo/summary) as follow:
#### Make your first clip from a spoken line

From the root of this source checkout, activate the FunClip environment from **Install**. Have a short video you are allowed to process and the corresponding Paraformer models ready. For Mandarin speech run:
```shell
python funclip/launch.py
# '-m fun-asr-nano' for the flagship Fun-ASR-Nano model (Mandarin, English,
# Japanese, 7 Chinese dialect groups, and 26 regional accents)
# '-m sensevoice' for SenseVoice model (multilingual ASR + emotion + audio event detection)
# '--model moss' for OpenMOSS long-form ASR + anonymous speaker labels + timestamps
# '-l en' for English audio recognize
# '-p xxx' for setting port number
# '-s True' for establishing service for public accessing
python funclip/launch.py --no-examples
```

For English speech add `-l en` and use the English model. Open `http://127.0.0.1:7860` on the same machine. The server stays local by default; no public share link or LLM key is needed. `--no-examples` skips downloading the hosted demo media, not model weights. A first model download needs permission and network access. Older source archives without this option need a newer checkout; check with `python funclip/launch.py --help`.

1. Choose your video in **Video Input**. A preview means the file is loaded, not transcribed. Click **ASR** and wait for text in **Recognition Result**.
2. In **Text/Speaker Clipping**, copy one continuous phrase from that result into **Text to Clip**. Click **Clip**. Choose **Clip+Subtitles** instead to burn captions into the video.
3. Play **Video Clipped** and check the clipped SRT against the phrase you chose. Its times refer to the clip. If the clipping log reports no match, copy the words from this transcript, not from memory.

For a speaker selection, use the recognition button with speaker labels and enter the returned speaker ID rather than a phrase. To use the hosted demo gallery instead of your own file, omit `--no-examples` and allow network access to the example media.

<img src="docs/images/guide.jpg"/>

#### Model selection quick start

| Scenario | Command |
Expand All @@ -120,15 +125,6 @@ MOSS performs segmentation and speaker diarization end to end. Its `spkS01`, `sp

If you only need offline speech transcription on CPU or edge devices and do not need FunClip's video clipping UI, use the FunASR llama.cpp / GGUF runtime instead: [funasr.com/llama-cpp](https://www.funasr.com/llama-cpp.html) · [Fun-ASR-Nano-GGUF](https://huggingface.co/FunAudioLLM/Fun-ASR-Nano-GGUF) · [SenseVoiceSmall-GGUF](https://huggingface.co/FunAudioLLM/SenseVoiceSmall-GGUF).

then visit ```localhost:7860``` you will get a Gradio service like below and you can use FunClip following the steps:

- Step1: Upload your video file (or try the example videos below)
- Step2: Copy the text segments you need to 'Text to Clip'
- Step3: Adjust subtitle settings (if needed)
- Step4: Click 'Clip' or 'Clip and Generate Subtitles'

<img src="docs/images/guide.jpg"/>

Follow the guide below to explore LLM based clipping:

<img src="docs/images/LLM_guide.png" width=360/>
Expand Down
33 changes: 15 additions & 18 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,23 @@ FunClip 当前模型与字幕兼容路径需要 `funasr>=1.4.9`,其中包括 M

### A.在本地启动Gradio服务

#### 按一句台词剪出第一个片段

在当前源码的仓库根目录,激活上文安装好的 FunClip 环境。准备一段有权处理的短视频,以及对应的 Paraformer 模型。普通话视频用:
```shell
python funclip/launch.py
# '-m fun-asr-nano' 使用旗舰版 Fun-ASR-Nano(普通话、英语、日语、
# 7 类中文方言和 26 种地域口音)
# '-m sensevoice' 使用 SenseVoice 模型(多语种 ASR + 情绪识别 + 音频事件检测)
# '--model moss' 使用 OpenMOSS 长音频 ASR + 匿名说话人标签 + 时间戳
# '-l en' for English audio recognize
# '-p xxx' for setting port number
# '-s True' for establishing service for public accessing
python funclip/launch.py --no-examples
```

英文语音请加 `-l en` 并准备英文模型。在同一台机器上打开 `http://127.0.0.1:7860`。默认只监听本机,不用开公网分享,也不需要 LLM 密钥。`--no-examples` 只跳过联网获取演示素材,不会替你准备模型权重。首次下载模型需要联网并获得许可。可用 `python funclip/launch.py --help` 查看当前源码是否支持此选项;不支持的旧归档需换用新版源码。

1. 在 **视频输入** 中选择视频。出现预览只表示文件已载入,不表示识别完成。点击 **识别(ASR)**,等 **识别结果** 中出现文字。
2. 切到 **根据文本/说话人裁剪**,从识别结果复制一句连续原文到 **待裁剪文本**,点击 **裁剪**。需要把字幕烧录到画面上时,改点 **裁剪+字幕**。
3. 播放 **裁剪结果**,核对片段和裁剪部分的 SRT 字幕是否对应所选台词。字幕时间相对于新片段。若裁剪信息提示没有匹配,先从本次识别结果重新复制原文。

按说话人剪辑时,先用“识别+区分说话人”,再填写识别结果里的说话人 ID,而不是台词。若想用在线演示素材代替自己的文件,可去掉 `--no-examples`,并允许获取示例媒体。

<img src="docs/images/guide.jpg"/>

#### 模型选择快速开始

| 场景 | 启动命令 |
Expand All @@ -121,16 +128,6 @@ MOSS 端到端完成分段与说话人分离。`spkS01`、`spkS02` 等值只是

如果你只需要在 CPU 或边缘设备上离线转写语音,而不需要 FunClip 的视频剪辑界面,请优先使用 FunASR llama.cpp / GGUF 运行时:[funasr.com/llama-cpp](https://www.funasr.com/llama-cpp.html) · [Fun-ASR-Nano-GGUF](https://huggingface.co/FunAudioLLM/Fun-ASR-Nano-GGUF) · [SenseVoiceSmall-GGUF](https://huggingface.co/FunAudioLLM/SenseVoiceSmall-GGUF)。

随后在浏览器中访问```localhost:7860```即可看到如下图所示的界面,按如下步骤即可进行视频剪辑
1. 上传你的视频(或使用下方的视频用例)
2. (可选)设置热词,设置文件输出路径(保存识别结果、视频等)
3. 点击识别按钮获取识别结果,或点击识别+区分说话人在语音识别基础上识别说话人ID
4. 将识别结果中的选段复制到对应位置,或者将说话人ID输入到对应为止
5. (可选)配置剪辑参数,偏移量与字幕设置等
6. 点击“裁剪”或“裁剪+字幕”按钮

<img src="docs/images/guide.jpg"/>

使用大语言模型裁剪请参考如下教程

<img src="docs/images/LLM_guide.png" width=360/>
Expand Down
24 changes: 13 additions & 11 deletions funclip/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def create_asr_model(model_name, lang, auto_model_cls=AutoModel, **kwargs):
parser.add_argument('--share', '-s', action='store_true', help="if to establish gradio share link")
parser.add_argument('--port', '-p', type=int, default=7860, help='port number')
parser.add_argument('--listen', action='store_true', help="if to listen to all hosts")
parser.add_argument('--no-examples', action='store_true', help="skip the remote demo media gallery; upload your own file")
args = parser.parse_args()

moss_api_key = os.environ.get(args.moss_api_key_env) if args.moss_api_key_env else None
Expand Down Expand Up @@ -221,17 +222,18 @@ def AI_clip_subti(LLM_res, dest_text, video_spk_input, start_ost, end_ost, video
video_input = gr.Video(label="视频输入 | Video Input")
audio_input = gr.Audio(label="音频输入 | Audio Input")
with gr.Column():
gr.Examples(['https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%A4%9A%E8%AF%BB%E4%B9%A6%EF%BC%9F%E8%BF%99%E6%98%AF%E6%88%91%E5%90%AC%E8%BF%87%E6%9C%80%E5%A5%BD%E7%9A%84%E7%AD%94%E6%A1%88-%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],
label='示例视频 | Demo Video')
gr.Examples(['https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E8%AE%BF%E8%B0%88.mp4'],
[video_input],
label='多说话人示例视频 | Multi-speaker Demo Video')
gr.Examples(['https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E9%B2%81%E8%82%83%E9%87%87%E8%AE%BF%E7%89%87%E6%AE%B51.wav'],
[audio_input],
label="示例音频 | Demo Audio")
if not args.no_examples:
gr.Examples(['https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%A4%9A%E8%AF%BB%E4%B9%A6%EF%BC%9F%E8%BF%99%E6%98%AF%E6%88%91%E5%90%AC%E8%BF%87%E6%9C%80%E5%A5%BD%E7%9A%84%E7%AD%94%E6%A1%88-%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],
label='示例视频 | Demo Video')
gr.Examples(['https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E8%AE%BF%E8%B0%88.mp4'],
[video_input],
label='多说话人示例视频 | Multi-speaker Demo Video')
gr.Examples(['https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ClipVideo/%E9%B2%81%E8%82%83%E9%87%87%E8%AE%BF%E7%89%87%E6%AE%B51.wav'],
[audio_input],
label="示例音频 | Demo Audio")
with gr.Column():
# with gr.Row():
# video_sd_switch = gr.Radio(["No", "Yes"], label="👥区分说话人 Get Speakers", value='No')
Expand Down
53 changes: 53 additions & 0 deletions tests/test_gradio_runtime_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import ast
from pathlib import Path
import runpy
import sys
from types import ModuleType
from unittest.mock import Mock

import pytest

ROOT = Path(__file__).resolve().parents[1]
LAUNCH_PATH = ROOT / "funclip" / "launch.py"
Expand Down Expand Up @@ -84,3 +90,50 @@ def test_launcher_does_not_patch_dependencies_or_retry_with_public_share():

assert len(launch_calls) == 1
assert patched_attributes == []


@pytest.mark.parametrize("options, expected_sizes", [([], [3, 1, 1]), (["--no-examples"], [])])
def test_local_upload_and_optional_demo_gallery(monkeypatch, options, expected_sizes):
monkeypatch.setenv("GRADIO_ANALYTICS_ENABLED", "False")
import gradio as gr

# Exercise the launcher and actual Gradio component graph without loading
# optional recognition/provider packages, downloading media or listening.
for module, name in (
("funasr", "AutoModel"), ("videoclipper", "VideoClipper"),
("model_selection", "create_asr_model"), ("llm.openai_api", "openai_call"),
("llm.qwen_api", "call_qwen_model"), ("llm.g4f_openai_api", "g4f_openai_call"),
("llm.litellm_api", "litellm_call"), ("llm.twelvelabs_api", "call_twelvelabs_pegasus"),
):
stub = ModuleType(module)
setattr(stub, name, Mock())
monkeypatch.setitem(sys.modules, module, stub)
gallery_sizes = []
configs = []

def examples(items, inputs, **kwargs):
assert all(url.startswith("https://") for url in items)
assert len(inputs) == 1 and isinstance(inputs[0], (gr.Audio, gr.Video))
gallery_sizes.append(len(items))

def launch(blocks, **kwargs):
assert kwargs["server_name"] == "127.0.0.1" and not kwargs["share"]
configs.append(blocks.get_config_file())

monkeypatch.setattr(gr, "Examples", examples)
monkeypatch.setattr(gr.Blocks, "launch", launch)
monkeypatch.chdir(ROOT)
monkeypatch.syspath_prepend(str(LAUNCH_PATH.parent))
monkeypatch.setattr(sys, "argv", [str(LAUNCH_PATH), *options])
runpy.run_path(str(LAUNCH_PATH), run_name="__main__")
assert gallery_sizes == expected_sizes
config, = configs
labels = {c["id"]: c["props"].get("label") or c["props"].get("value") for c in config["components"]}
assert any("Video Input" in str(label) for label in labels.values())
assert any("Audio Input" in str(label) for label in labels.values())
for button, output in ((" | ASR", "Recognition Result"), (" | Clip", "Video Clipped")):
assert any(
any(event == "click" and str(labels.get(i)).endswith(button) for i, event in dep["targets"])
and any(output in str(labels[i]) for i in dep["outputs"])
for dep in config["dependencies"]
)