voxprep 0.1.0.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of voxprep might be problematic. Click here for more details.

Files changed (37) hide show
  1. voxprep-0.1.0.dev0/.gitignore +15 -0
  2. voxprep-0.1.0.dev0/.python-version +1 -0
  3. voxprep-0.1.0.dev0/LICENSE +21 -0
  4. voxprep-0.1.0.dev0/PKG-INFO +183 -0
  5. voxprep-0.1.0.dev0/README.md +156 -0
  6. voxprep-0.1.0.dev0/README_ZH.md +148 -0
  7. voxprep-0.1.0.dev0/benchmarks/bench_correctness.py +159 -0
  8. voxprep-0.1.0.dev0/docs/PLAN.md +240 -0
  9. voxprep-0.1.0.dev0/docs/agents.md +56 -0
  10. voxprep-0.1.0.dev0/pyproject.toml +67 -0
  11. voxprep-0.1.0.dev0/skills/voxprep/SKILL.md +40 -0
  12. voxprep-0.1.0.dev0/src/voxprep/__init__.py +42 -0
  13. voxprep-0.1.0.dev0/src/voxprep/backends/__init__.py +43 -0
  14. voxprep-0.1.0.dev0/src/voxprep/backends/funasr.py +53 -0
  15. voxprep-0.1.0.dev0/src/voxprep/backends/openai.py +84 -0
  16. voxprep-0.1.0.dev0/src/voxprep/chunker.py +421 -0
  17. voxprep-0.1.0.dev0/src/voxprep/cli.py +311 -0
  18. voxprep-0.1.0.dev0/src/voxprep/diagnose.py +130 -0
  19. voxprep-0.1.0.dev0/src/voxprep/io.py +226 -0
  20. voxprep-0.1.0.dev0/src/voxprep/models/SILERO_VAD_LICENSE +21 -0
  21. voxprep-0.1.0.dev0/src/voxprep/models/__init__.py +0 -0
  22. voxprep-0.1.0.dev0/src/voxprep/models/silero_vad_16k_op15.onnx +0 -0
  23. voxprep-0.1.0.dev0/src/voxprep/presets.py +196 -0
  24. voxprep-0.1.0.dev0/src/voxprep/py.typed +0 -0
  25. voxprep-0.1.0.dev0/src/voxprep/reference.py +220 -0
  26. voxprep-0.1.0.dev0/src/voxprep/stitch.py +204 -0
  27. voxprep-0.1.0.dev0/src/voxprep/transcript.py +294 -0
  28. voxprep-0.1.0.dev0/src/voxprep/vad.py +186 -0
  29. voxprep-0.1.0.dev0/tests/conftest.py +61 -0
  30. voxprep-0.1.0.dev0/tests/data/speech_en.wav +0 -0
  31. voxprep-0.1.0.dev0/tests/test_chunker.py +121 -0
  32. voxprep-0.1.0.dev0/tests/test_io.py +63 -0
  33. voxprep-0.1.0.dev0/tests/test_presets_inspect.py +83 -0
  34. voxprep-0.1.0.dev0/tests/test_reference.py +79 -0
  35. voxprep-0.1.0.dev0/tests/test_stitch_backends.py +295 -0
  36. voxprep-0.1.0.dev0/tests/test_transcript.py +93 -0
  37. voxprep-0.1.0.dev0/tests/test_vad.py +73 -0
@@ -0,0 +1,15 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Private research (kept local, not published)
13
+ reports/
14
+ research_notes/
15
+ docs/RESEARCH.md
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LL333111
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.5
2
+ Name: voxprep
3
+ Version: 0.1.0.dev0
4
+ Summary: Get any audio or video into an AI model, and the results back on the original timeline. No PyTorch, no system FFmpeg.
5
+ Author: LL333111
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: asr,audio,chunking,llm,subtitles,transcription,vad,voice-clone,whisper
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
16
+ Requires-Python: >=3.12
17
+ Requires-Dist: av>=14.0
18
+ Requires-Dist: numpy>=1.26
19
+ Requires-Dist: onnxruntime>=1.20
20
+ Provides-Extra: funasr
21
+ Requires-Dist: funasr>=1.1; extra == 'funasr'
22
+ Provides-Extra: groq
23
+ Requires-Dist: openai>=1.50; extra == 'groq'
24
+ Provides-Extra: openai
25
+ Requires-Dist: openai>=1.50; extra == 'openai'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # voxprep
29
+
30
+ Get any audio or video file into an AI model, and get the results back on the original timeline.
31
+
32
+ [中文](README_ZH.md)
33
+
34
+ ```console
35
+ $ voxprep subtitle meeting.mp4 --via groq
36
+ voxprep: transcribing meeting.mp4 via groq …
37
+ ✓ chunk 1/2 (0–1204 s)
38
+ ✓ chunk 2/2 (1204–1458 s)
39
+ → meeting.srt (200 segments, ~2893 LLM tokens)
40
+ ```
41
+
42
+ A 24-minute video is too big for Groq's 25 MB limit. voxprep decoded it, split it at a pause,
43
+ sent both halves, and shifted the second half's timestamps by 1204 s so the subtitles line up
44
+ with the video.
45
+
46
+ voxprep doesn't do speech recognition itself. It handles the work around the model:
47
+
48
+ - **Before**: decode anything FFmpeg can read, re-encode to what the model wants, split at
49
+ pauses only when the file is over the model's size or length limit.
50
+ - **After**: put each chunk's timestamps back on the source timeline, merge fragments into
51
+ readable cues, and export SRT, VTT, Markdown, JSON, or a Claude document block.
52
+
53
+ It needs only numpy, PyAV (which bundles FFmpeg) and onnxruntime. No PyTorch, no system FFmpeg.
54
+
55
+ ## Install
56
+
57
+ ```bash
58
+ pip install --pre voxprep # early alpha; drop --pre once 0.1.0 is out
59
+ pip install --pre "voxprep[openai]" # for the OpenAI and Groq backends
60
+ pip install --pre "voxprep[funasr]" # for local SenseVoice (this one pulls in PyTorch)
61
+ ```
62
+
63
+ Python 3.12+ on Windows, macOS or Linux.
64
+
65
+ ## Usage
66
+
67
+ Built-in backends do everything in one call:
68
+
69
+ ```bash
70
+ voxprep subtitle talk.mp4 --via openai # writes talk.srt (needs OPENAI_API_KEY)
71
+ voxprep transcribe talk.mp4 --via groq -f md # GROQ_API_KEY; formats: srt vtt md txt json claude
72
+ voxprep transcribe talk.mp4 --via funasr # local, no key
73
+ ```
74
+
75
+ For any other model, let voxprep prepare the audio and call the model yourself:
76
+
77
+ ```python
78
+ import voxprep as vp
79
+
80
+ result = vp.prepare("call.m4a", target="openai") # or max_mb=..., max_seconds=..., fmt=...
81
+ texts = [my_model(chunk.to_bytes()) for chunk in result.chunks]
82
+ vp.stitch(result, texts).refine().to_srt("call.srt")
83
+ ```
84
+
85
+ `stitch` takes whatever your model returns: OpenAI-style JSON with segments, SRT or VTT,
86
+ or plain text. Plain text without timestamps gets spread over the detected speech in that chunk.
87
+
88
+ The same works from the command line:
89
+
90
+ ```bash
91
+ voxprep prepare talk.mp4 --for custom --max-mb 10 --max-sec 300 --format wav -o chunks
92
+ # ...send chunks/chunk_000.wav etc. to your model, save answers as chunks/chunk_000.txt...
93
+ voxprep stitch chunks -o talk.srt
94
+ ```
95
+
96
+ Other commands:
97
+
98
+ ```bash
99
+ voxprep inspect talk.mp4 # duration, format, silence, which models take it as is
100
+ voxprep presets # every preset and its limits
101
+ voxprep ref-clip podcast.mp4 --for f5 # cleanest 3-12 s clip for voice cloning, as ref.wav
102
+ ```
103
+
104
+ Every command takes `--json`.
105
+
106
+ ## Supported models
107
+
108
+ | Preset | Model | Limit voxprep keeps to |
109
+ | --- | --- | --- |
110
+ | `openai` | OpenAI transcription (gpt-transcribe, whisper-1, gpt-4o-*-transcribe) | 24 MB |
111
+ | `groq` | Groq Whisper | 24 MB; avoids chunks under 10 s (billed as 10 s) |
112
+ | `gemini` | Gemini audio, inline | 14 MB, 9.5 h |
113
+ | `sensevoice` | SenseVoice / FunASR | 28 s |
114
+ | `qwen3-asr-flash` | Qwen3-ASR-Flash | 9.5 MB, 290 s (not verified yet) |
115
+ | `f5`, `cosyvoice`, `qwen3-tts`, `generic` | Voice-clone reference clips | 3-30 s depending on model |
116
+
117
+ Anything else: `--for custom` with your own `--max-mb`, `--max-sec`, `--rate` and `--format`.
118
+
119
+ ## Claude, ChatGPT, DeepSeek and other text models
120
+
121
+ Most chat models can't take audio. Transcribe first, then hand them the text:
122
+
123
+ ```python
124
+ t = vp.transcribe("meeting.mp4", via="groq")
125
+ t.to_markdown() # "[00:12:41] text" lines, for any model
126
+ t.estimate_tokens() # will it fit in the context window?
127
+ ```
128
+
129
+ With Claude you can also get citations back to the exact moment in the recording:
130
+
131
+ ```python
132
+ import anthropic
133
+
134
+ msg = anthropic.Anthropic().messages.create(
135
+ model="claude-opus-5-5",
136
+ max_tokens=2000,
137
+ messages=[{"role": "user", "content": [
138
+ t.to_claude(title="Weekly meeting"), # document block with citations on
139
+ {"type": "text", "text": "What did we decide about the launch date?"},
140
+ ]}],
141
+ )
142
+ for block in msg.content:
143
+ if block.type == "text":
144
+ print(block.text)
145
+ for c in block.citations or []:
146
+ start, end = t.locate(c) # seconds in the recording
147
+ print(f" at {start:.0f}s")
148
+ ```
149
+
150
+ ## Coding agents
151
+
152
+ Claude Code, Cursor and the like can't listen to a file, but they can run voxprep.
153
+
154
+ - Claude Code: copy [`skills/voxprep/`](skills/voxprep/SKILL.md) into `~/.claude/skills/`.
155
+ - Others: paste the snippet from [docs/agents.md](docs/agents.md) into your `AGENTS.md` or rules file.
156
+
157
+ ## Compared with
158
+
159
+ - **pydub + a loop**: needs system FFmpeg, and you still have to work out each API's limits and
160
+ fix the timestamps yourself.
161
+ - **silero-vad**: great VAD, but pulls in PyTorch. voxprep runs the same model through onnxruntime.
162
+ - **faster-whisper / WhisperX**: the right choice for running Whisper locally. They chunk
163
+ internally, so voxprep isn't needed there.
164
+
165
+ ## Testing
166
+
167
+ ```bash
168
+ uv run pytest
169
+ uv run python benchmarks/bench_correctness.py
170
+ ```
171
+
172
+ The benchmark checks that every chunk stays under its preset's limits, that every cut falls
173
+ in a pause, and that stitched timestamps match the source (within 1 ms).
174
+
175
+ ## Notes
176
+
177
+ - Silero VAD v6 (MIT) ships inside the package. Where onnxruntime isn't available, voxprep
178
+ falls back to a simple energy-based VAD.
179
+ - PyAV wheels include FFmpeg libraries (LGPL). Worth checking if you redistribute voxprep in
180
+ another product.
181
+ - Provider limits change. Each preset records its source and when it was checked.
182
+
183
+ MIT license.
@@ -0,0 +1,156 @@
1
+ # voxprep
2
+
3
+ Get any audio or video file into an AI model, and get the results back on the original timeline.
4
+
5
+ [中文](README_ZH.md)
6
+
7
+ ```console
8
+ $ voxprep subtitle meeting.mp4 --via groq
9
+ voxprep: transcribing meeting.mp4 via groq …
10
+ ✓ chunk 1/2 (0–1204 s)
11
+ ✓ chunk 2/2 (1204–1458 s)
12
+ → meeting.srt (200 segments, ~2893 LLM tokens)
13
+ ```
14
+
15
+ A 24-minute video is too big for Groq's 25 MB limit. voxprep decoded it, split it at a pause,
16
+ sent both halves, and shifted the second half's timestamps by 1204 s so the subtitles line up
17
+ with the video.
18
+
19
+ voxprep doesn't do speech recognition itself. It handles the work around the model:
20
+
21
+ - **Before**: decode anything FFmpeg can read, re-encode to what the model wants, split at
22
+ pauses only when the file is over the model's size or length limit.
23
+ - **After**: put each chunk's timestamps back on the source timeline, merge fragments into
24
+ readable cues, and export SRT, VTT, Markdown, JSON, or a Claude document block.
25
+
26
+ It needs only numpy, PyAV (which bundles FFmpeg) and onnxruntime. No PyTorch, no system FFmpeg.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ pip install --pre voxprep # early alpha; drop --pre once 0.1.0 is out
32
+ pip install --pre "voxprep[openai]" # for the OpenAI and Groq backends
33
+ pip install --pre "voxprep[funasr]" # for local SenseVoice (this one pulls in PyTorch)
34
+ ```
35
+
36
+ Python 3.12+ on Windows, macOS or Linux.
37
+
38
+ ## Usage
39
+
40
+ Built-in backends do everything in one call:
41
+
42
+ ```bash
43
+ voxprep subtitle talk.mp4 --via openai # writes talk.srt (needs OPENAI_API_KEY)
44
+ voxprep transcribe talk.mp4 --via groq -f md # GROQ_API_KEY; formats: srt vtt md txt json claude
45
+ voxprep transcribe talk.mp4 --via funasr # local, no key
46
+ ```
47
+
48
+ For any other model, let voxprep prepare the audio and call the model yourself:
49
+
50
+ ```python
51
+ import voxprep as vp
52
+
53
+ result = vp.prepare("call.m4a", target="openai") # or max_mb=..., max_seconds=..., fmt=...
54
+ texts = [my_model(chunk.to_bytes()) for chunk in result.chunks]
55
+ vp.stitch(result, texts).refine().to_srt("call.srt")
56
+ ```
57
+
58
+ `stitch` takes whatever your model returns: OpenAI-style JSON with segments, SRT or VTT,
59
+ or plain text. Plain text without timestamps gets spread over the detected speech in that chunk.
60
+
61
+ The same works from the command line:
62
+
63
+ ```bash
64
+ voxprep prepare talk.mp4 --for custom --max-mb 10 --max-sec 300 --format wav -o chunks
65
+ # ...send chunks/chunk_000.wav etc. to your model, save answers as chunks/chunk_000.txt...
66
+ voxprep stitch chunks -o talk.srt
67
+ ```
68
+
69
+ Other commands:
70
+
71
+ ```bash
72
+ voxprep inspect talk.mp4 # duration, format, silence, which models take it as is
73
+ voxprep presets # every preset and its limits
74
+ voxprep ref-clip podcast.mp4 --for f5 # cleanest 3-12 s clip for voice cloning, as ref.wav
75
+ ```
76
+
77
+ Every command takes `--json`.
78
+
79
+ ## Supported models
80
+
81
+ | Preset | Model | Limit voxprep keeps to |
82
+ | --- | --- | --- |
83
+ | `openai` | OpenAI transcription (gpt-transcribe, whisper-1, gpt-4o-*-transcribe) | 24 MB |
84
+ | `groq` | Groq Whisper | 24 MB; avoids chunks under 10 s (billed as 10 s) |
85
+ | `gemini` | Gemini audio, inline | 14 MB, 9.5 h |
86
+ | `sensevoice` | SenseVoice / FunASR | 28 s |
87
+ | `qwen3-asr-flash` | Qwen3-ASR-Flash | 9.5 MB, 290 s (not verified yet) |
88
+ | `f5`, `cosyvoice`, `qwen3-tts`, `generic` | Voice-clone reference clips | 3-30 s depending on model |
89
+
90
+ Anything else: `--for custom` with your own `--max-mb`, `--max-sec`, `--rate` and `--format`.
91
+
92
+ ## Claude, ChatGPT, DeepSeek and other text models
93
+
94
+ Most chat models can't take audio. Transcribe first, then hand them the text:
95
+
96
+ ```python
97
+ t = vp.transcribe("meeting.mp4", via="groq")
98
+ t.to_markdown() # "[00:12:41] text" lines, for any model
99
+ t.estimate_tokens() # will it fit in the context window?
100
+ ```
101
+
102
+ With Claude you can also get citations back to the exact moment in the recording:
103
+
104
+ ```python
105
+ import anthropic
106
+
107
+ msg = anthropic.Anthropic().messages.create(
108
+ model="claude-opus-5-5",
109
+ max_tokens=2000,
110
+ messages=[{"role": "user", "content": [
111
+ t.to_claude(title="Weekly meeting"), # document block with citations on
112
+ {"type": "text", "text": "What did we decide about the launch date?"},
113
+ ]}],
114
+ )
115
+ for block in msg.content:
116
+ if block.type == "text":
117
+ print(block.text)
118
+ for c in block.citations or []:
119
+ start, end = t.locate(c) # seconds in the recording
120
+ print(f" at {start:.0f}s")
121
+ ```
122
+
123
+ ## Coding agents
124
+
125
+ Claude Code, Cursor and the like can't listen to a file, but they can run voxprep.
126
+
127
+ - Claude Code: copy [`skills/voxprep/`](skills/voxprep/SKILL.md) into `~/.claude/skills/`.
128
+ - Others: paste the snippet from [docs/agents.md](docs/agents.md) into your `AGENTS.md` or rules file.
129
+
130
+ ## Compared with
131
+
132
+ - **pydub + a loop**: needs system FFmpeg, and you still have to work out each API's limits and
133
+ fix the timestamps yourself.
134
+ - **silero-vad**: great VAD, but pulls in PyTorch. voxprep runs the same model through onnxruntime.
135
+ - **faster-whisper / WhisperX**: the right choice for running Whisper locally. They chunk
136
+ internally, so voxprep isn't needed there.
137
+
138
+ ## Testing
139
+
140
+ ```bash
141
+ uv run pytest
142
+ uv run python benchmarks/bench_correctness.py
143
+ ```
144
+
145
+ The benchmark checks that every chunk stays under its preset's limits, that every cut falls
146
+ in a pause, and that stitched timestamps match the source (within 1 ms).
147
+
148
+ ## Notes
149
+
150
+ - Silero VAD v6 (MIT) ships inside the package. Where onnxruntime isn't available, voxprep
151
+ falls back to a simple energy-based VAD.
152
+ - PyAV wheels include FFmpeg libraries (LGPL). Worth checking if you redistribute voxprep in
153
+ another product.
154
+ - Provider limits change. Each preset records its source and when it was checked.
155
+
156
+ MIT license.
@@ -0,0 +1,148 @@
1
+ # voxprep
2
+
3
+ 把任何音视频交给 AI 模型,再把结果对回原来的时间轴。
4
+
5
+ [English](README.md)
6
+
7
+ ```console
8
+ $ voxprep subtitle 会议.mp4 --via groq
9
+ voxprep: transcribing 会议.mp4 via groq …
10
+ ✓ chunk 1/2 (0–1204 s)
11
+ ✓ chunk 2/2 (1204–1458 s)
12
+ → 会议.srt (200 segments, ~2893 LLM tokens)
13
+ ```
14
+
15
+ 这段 24 分钟的视频超过了 Groq 的 25 MB 上限。voxprep 先解码,在一处停顿把它切成两段,分别发出去;
16
+ 拿回结果后,把第二段的时间戳加上 1204 秒,字幕就和视频对上了。
17
+
18
+ voxprep 不做语音识别,它负责模型前后的那些活:
19
+
20
+ - **之前**:解码 FFmpeg 能读的任何格式,转成模型要的格式;只有超过模型的大小或时长限制时才切,而且只在停顿处切。
21
+ - **之后**:把每段的时间戳还原到原文件上,把碎句合并成好读的字幕,导出 SRT、VTT、Markdown、JSON,或者 Claude 的 document 块。
22
+
23
+ 依赖只有 numpy、PyAV(自带 FFmpeg)和 onnxruntime。不装 PyTorch,也不用装系统 FFmpeg。
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install --pre voxprep # 目前是早期预览版,0.1.0 发布后去掉 --pre
29
+ pip install --pre "voxprep[openai]" # OpenAI 和 Groq 后端
30
+ pip install --pre "voxprep[funasr]" # 本地 SenseVoice(这个会装 PyTorch)
31
+ ```
32
+
33
+ 需要 Python 3.12+,Windows、macOS、Linux 都能用。
34
+
35
+ ## 用法
36
+
37
+ 内置后端一条命令搞定:
38
+
39
+ ```bash
40
+ voxprep subtitle 讲座.mp4 --via openai # 输出 讲座.srt(需要 OPENAI_API_KEY)
41
+ voxprep transcribe 讲座.mp4 --via groq -f md # 需要 GROQ_API_KEY;格式:srt vtt md txt json claude
42
+ voxprep transcribe 讲座.mp4 --via funasr # 本地运行,不需要 key
43
+ ```
44
+
45
+ 其他模型:让 voxprep 准备好音频,你自己调用模型:
46
+
47
+ ```python
48
+ import voxprep as vp
49
+
50
+ result = vp.prepare("通话.m4a", target="openai") # 或者 max_mb=..., max_seconds=..., fmt=...
51
+ texts = [my_model(chunk.to_bytes()) for chunk in result.chunks]
52
+ vp.stitch(result, texts).refine().to_srt("通话.srt")
53
+ ```
54
+
55
+ 模型返回什么,`stitch` 基本都能接:带分段的 OpenAI 风格 JSON、SRT、VTT,或者纯文本。
56
+ 没有时间戳的纯文本,会按句子分布到这一段检测到的人声上。
57
+
58
+ 命令行也一样:
59
+
60
+ ```bash
61
+ voxprep prepare 讲座.mp4 --for custom --max-mb 10 --max-sec 300 --format wav -o chunks
62
+ # ……把 chunks/chunk_000.wav 等发给你的模型,结果存成 chunks/chunk_000.txt……
63
+ voxprep stitch chunks -o 讲座.srt
64
+ ```
65
+
66
+ 其他命令:
67
+
68
+ ```bash
69
+ voxprep inspect 讲座.mp4 # 时长、格式、静音比例,以及哪些模型能直接用
70
+ voxprep presets # 所有 preset 及其限制
71
+ voxprep ref-clip 播客.mp4 --for cosyvoice # 挑出最干净的一段做声音克隆参考,存成 ref.wav
72
+ ```
73
+
74
+ 所有命令都可以加 `--json`。
75
+
76
+ ## 支持的模型
77
+
78
+ | Preset | 模型 | voxprep 遵守的限制 |
79
+ | --- | --- | --- |
80
+ | `openai` | OpenAI 转写(gpt-transcribe、whisper-1、gpt-4o-*-transcribe) | 24 MB |
81
+ | `groq` | Groq Whisper | 24 MB;避免出现不足 10 秒的段(按 10 秒计费) |
82
+ | `gemini` | Gemini 音频(直接上传) | 14 MB,9.5 小时 |
83
+ | `sensevoice` | SenseVoice / FunASR | 28 秒 |
84
+ | `qwen3-asr-flash` | 通义 Qwen3-ASR-Flash | 9.5 MB,290 秒(尚未核实) |
85
+ | `f5`、`cosyvoice`、`qwen3-tts`、`generic` | 声音克隆参考片段 | 3–30 秒,看具体模型 |
86
+
87
+ 其他模型用 `--for custom`,自己指定 `--max-mb`、`--max-sec`、`--rate`、`--format`。
88
+
89
+ ## Claude、ChatGPT、DeepSeek 等文字模型
90
+
91
+ 大多数聊天模型不接受音频。先转成文字稿,再交给它们:
92
+
93
+ ```python
94
+ t = vp.transcribe("会议.mp4", via="groq")
95
+ t.to_markdown() # "[00:12:41] 文本" 格式,任何模型都能用
96
+ t.estimate_tokens() # 能不能放进上下文窗口
97
+ ```
98
+
99
+ 用 Claude 的话,还能让它的每条引用都对应到录音里的具体时刻:
100
+
101
+ ```python
102
+ import anthropic
103
+
104
+ msg = anthropic.Anthropic().messages.create(
105
+ model="claude-opus-5-5",
106
+ max_tokens=2000,
107
+ messages=[{"role": "user", "content": [
108
+ t.to_claude(title="周会"), # 开启 citations 的 document 块
109
+ {"type": "text", "text": "上线日期最后怎么定的?"},
110
+ ]}],
111
+ )
112
+ for block in msg.content:
113
+ if block.type == "text":
114
+ print(block.text)
115
+ for c in block.citations or []:
116
+ start, end = t.locate(c) # 录音里的秒数
117
+ print(f" 在第 {start:.0f} 秒")
118
+ ```
119
+
120
+ ## 在编程 agent 里用
121
+
122
+ Claude Code、Cursor 这类 agent 自己听不了音频,但能运行 voxprep。
123
+
124
+ - Claude Code:把 [`skills/voxprep/`](skills/voxprep/SKILL.md) 复制到 `~/.claude/skills/`。
125
+ - 其他 agent:把 [docs/agents.md](docs/agents.md) 里的片段贴进 `AGENTS.md` 或规则文件。
126
+
127
+ ## 和其他工具比
128
+
129
+ - **pydub 加手写循环**:要装系统 FFmpeg,各家 API 的限制要自己查,时间戳也要自己对。
130
+ - **silero-vad**:VAD 本身很好,但依赖 PyTorch。voxprep 通过 onnxruntime 跑同一个模型。
131
+ - **faster-whisper / WhisperX**:本地跑 Whisper 就用它们。它们内部已经会切分,用不着 voxprep。
132
+
133
+ ## 测试
134
+
135
+ ```bash
136
+ uv run pytest
137
+ uv run python benchmarks/bench_correctness.py
138
+ ```
139
+
140
+ benchmark 检查三件事:每段都不超过 preset 的限制,每个切点都在停顿上,拼回后的时间戳和原文件一致(误差 1 毫秒以内)。
141
+
142
+ ## 说明
143
+
144
+ - 包里自带 Silero VAD v6 模型(MIT)。平台上没有 onnxruntime 时,会退回一个简单的能量检测 VAD。
145
+ - PyAV 的 wheel 里带有 FFmpeg 库(LGPL)。如果要把 voxprep 打包进别的产品分发,请留意这一点。
146
+ - 各家的限制会变。每个 preset 都记录了来源和核实日期。
147
+
148
+ MIT 许可证。
@@ -0,0 +1,159 @@
1
+ """Correctness and speed benchmark for voxprep.
2
+
3
+ uv run python benchmarks/bench_correctness.py [--minutes 20] [--file some.mp4] [--json]
4
+
5
+ Builds a long recording with known speech positions (the test speech clip repeated with random
6
+ pauses and background noise), then for every transcription preset checks:
7
+
8
+ * limits - every chunk is within the preset's size and duration limits
9
+ * cuts - each cut lands in a pause, not inside a word (60 ms RMS around the cut is quiet)
10
+ * stitch - per-chunk timestamps map back to the source exactly (max error, ms), also with
11
+ --strip-silence
12
+ * speed - decode + VAD + encode, as a multiple of realtime
13
+
14
+ With --file, the same limit and cut checks also run on a real recording.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import argparse
20
+ import json
21
+ import sys
22
+ import time
23
+ from pathlib import Path
24
+
25
+ import numpy as np
26
+
27
+ import voxprep as vp
28
+ from voxprep import presets, vad
29
+ from voxprep.io import Audio
30
+
31
+ ROOT = Path(__file__).resolve().parents[1]
32
+ CLIP = ROOT / "tests" / "data" / "speech_en.wav"
33
+ SR = 16000
34
+
35
+
36
+ def synth(minutes: float, seed: int = 0) -> tuple[Audio, list[tuple[float, float]]]:
37
+ """Speech clip repeated with 0.4–3 s pauses in light noise; returns audio and speech spans."""
38
+ rng = np.random.default_rng(seed)
39
+ clip = vp.load(CLIP)
40
+ inner = vad.detect(clip) # the clip's own sentences
41
+ parts, truth, t = [], [], 0.0
42
+ while t < minutes * 60:
43
+ gap = rng.uniform(0.4, 3.0)
44
+ parts.append(np.zeros(int(gap * SR), np.float32))
45
+ t += gap
46
+ gain = rng.uniform(0.5, 1.0)
47
+ parts.append(clip.samples * gain)
48
+ truth += [(t + s.start, t + s.end) for s in inner]
49
+ t += clip.duration
50
+ x = np.concatenate(parts)
51
+ x = x + rng.standard_normal(len(x)).astype(np.float32) * 0.002
52
+ return Audio(x, SR), truth
53
+
54
+
55
+ def quiet_at(audio: Audio, t: float, half: float = 0.03) -> bool:
56
+ x = audio.slice(max(0.0, t - half), t + half).samples
57
+ return float(np.sqrt(np.mean(x**2))) < 0.01
58
+
59
+
60
+ def to_local(chunk, src: float) -> float | None:
61
+ for p in chunk.pieces:
62
+ if p.source_start <= src <= p.source_start + p.duration:
63
+ return p.local_start + (src - p.source_start)
64
+ return None
65
+
66
+
67
+ def stitch_error(audio: Audio, truth, result) -> float:
68
+ """Fake per-chunk ASR output at the true speech times, stitch, return max error in ms."""
69
+ per_chunk, expected = [], []
70
+ for c in result.chunks:
71
+ segs = []
72
+ for i, (a, b) in enumerate(truth):
73
+ la, lb = to_local(c, a), to_local(c, b)
74
+ if la is None or lb is None or not (c.start <= a and b <= c.end):
75
+ continue
76
+ segs.append({"start": la, "end": lb, "text": f"u{i}"})
77
+ expected.append((a, b))
78
+ per_chunk.append({"segments": segs, "text": " ".join(s["text"] for s in segs)})
79
+ t = vp.stitch(result, per_chunk)
80
+ got = [(s.start, s.end) for s in t.segments]
81
+ if len(got) != len(expected):
82
+ return float("inf")
83
+ err = max(max(abs(g[0] - e[0]), abs(g[1] - e[1])) for g, e in zip(got, expected, strict=True))
84
+ return err * 1000
85
+
86
+
87
+ def check(audio: Audio, preset: str, strip: bool = False, truth=None) -> dict:
88
+ p = presets.get(preset)
89
+ t0 = time.perf_counter()
90
+ r = vp.prepare(audio, preset, strip_silence=strip)
91
+ for c in r.chunks:
92
+ c.to_bytes()
93
+ elapsed = time.perf_counter() - t0
94
+ cuts = [c.start for c in r.chunks[1:]]
95
+ row = {
96
+ "preset": preset + (" +strip" if strip else ""),
97
+ "chunks": len(r.chunks),
98
+ "max_mb": round(max(c.size_bytes for c in r.chunks) / 1e6, 2),
99
+ "max_sec": round(max(c.duration for c in r.chunks), 1),
100
+ "within_limits": all(
101
+ (p.max_bytes is None or c.size_bytes <= p.max_bytes)
102
+ and (p.max_seconds is None or c.duration <= p.max_seconds)
103
+ for c in r.chunks
104
+ ),
105
+ "cuts": len(cuts),
106
+ "cuts_in_pause": sum(quiet_at(audio, t) for t in cuts),
107
+ "speed_x": round(audio.duration / elapsed, 1),
108
+ }
109
+ if truth is not None:
110
+ row["stitch_err_ms"] = round(stitch_error(audio, truth, r), 3)
111
+ return row
112
+
113
+
114
+ def main(argv=None) -> int:
115
+ ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
116
+ ap.add_argument("--minutes", type=float, default=20)
117
+ ap.add_argument("--file", help="also check a real recording")
118
+ ap.add_argument("--json", action="store_true")
119
+ args = ap.parse_args(argv)
120
+
121
+ audio, truth = synth(args.minutes)
122
+ rows = [check(audio, name, truth=truth) for name in presets.TRANSCRIBE]
123
+ rows.append(check(audio, "gemini", strip=True, truth=truth))
124
+ rows.append(check(audio, "sensevoice", strip=True, truth=truth))
125
+ if args.file:
126
+ real = vp.load(args.file)
127
+ rows += [{**check(real, n), "file": Path(args.file).name} for n in ("openai", "sensevoice")]
128
+
129
+ ok = all(
130
+ r["within_limits"] and r["cuts_in_pause"] == r["cuts"] and r.get("stitch_err_ms", 0) < 1.0
131
+ for r in rows
132
+ if "file" not in r
133
+ )
134
+ if args.json:
135
+ print(json.dumps({"minutes": args.minutes, "ok": ok, "rows": rows}, indent=2))
136
+ else:
137
+ print(f"synthetic recording: {audio.duration / 60:.1f} min, {len(truth)} utterances\n")
138
+ cols = [
139
+ "preset",
140
+ "chunks",
141
+ "max_mb",
142
+ "max_sec",
143
+ "within_limits",
144
+ "cuts",
145
+ "cuts_in_pause",
146
+ "stitch_err_ms",
147
+ "speed_x",
148
+ ]
149
+ print(" ".join(f"{c:>14}" for c in cols))
150
+ for r in rows:
151
+ label = r["preset"] + (f" ({r['file']})" if "file" in r else "")
152
+ vals = [label] + [r.get(c, "-") for c in cols[1:]]
153
+ print(" ".join(f"{str(v):>14}" for v in vals))
154
+ print("\nPASS" if ok else "\nFAIL")
155
+ return 0 if ok else 1
156
+
157
+
158
+ if __name__ == "__main__":
159
+ sys.exit(main())