dysub-core
DySub 核心库 — 本地音频提取、ASR 转写与字幕合并的一站式解决方案。
简介
dysub-core 是 DySub 字幕提取工具的核心引擎,负责:
- 音频处理:基于 FFmpeg 流式提取、重采样、智能分片
- ASR 客户端:兼容 OpenAI 规范,支持 Whisper / DashScope 等服务商
- 字幕合并:SRT/VTT 时间戳修正与格式导出
- 流水线编排:纯 asyncio 异步驱动,带进度回调
- CLI 入口:
dysub命令行工具
安装
pip install dysub-core
前置依赖:
- Python 3.10+
- FFmpeg(
ffmpeg -version验证)
快速开始
CLI
# 检查环境
dysub doctor
# 本地视频转字幕
dysub process ./video.mp4 --lang zh --format srt
# 启动本地 WebUI
dysub webui
Python API
import asyncio
from pathlib import Path
from dysub_core.models import MediaSource, TaskConfig
from dysub_core.pipeline import Pipeline
async def main():
config = TaskConfig(
api_key="sk-xxxxxxxx",
base_url="https://dashscope.aliyuncs.com/api/v1",
language="zh",
output_format="srt",
output_dir=Path("outputs"),
)
pipeline = Pipeline(config)
source = MediaSource(
stream_url="./video.mp4",
source_type="local",
)
result = await pipeline.run(source)
print(f"Subtitle saved to: {result}")
asyncio.run(main())
配置 API Key
DySub 需要自备 ASR API Key。推荐阿里百炼(DashScope):
- 打开 阿里百炼控制台
- 进入「API Key 管理」→ 创建新的 API Key
- 配置到 DySub:
# 环境变量
export DYSUB_ASR_API_KEY="sk-xxxxxxxx"
export DYSUB_ASR_BASE_URL="https://dashscope.aliyuncs.com/api/v1"
# 或写入 ~/.config/dysub/.env
cat > ~/.config/dysub/.env << 'EOF'
DYSUB_ASR_API_KEY=sk-xxxxxxxx
DYSUB_ASR_BASE_URL=https://dashscope.aliyuncs.com/api/v1
DYSUB_DEFAULT_LANGUAGE=zh
DYSUB_DEFAULT_FORMAT=srt
EOF
功能特性
| 模块 | 能力 |
|---|---|
audio.processor |
FFmpeg 流式提取 → WAV (16kHz, mono),自动分片 (>25MB 按 10min 切) |
asr.client |
OpenAI 兼容客户端,支持 response_format=srt/vtt |
asr.dashscope_client |
阿里百岭 DashScope 原生客户端,支持 base64 音频上传 |
subtitle.merger |
SRT 分片合并,自动修正时间戳偏移 |
pipeline |
asyncio 异步流水线,并发控制,进度回调 |
cli |
Typer + Rich 终端界面,支持 doctor/process/webui |
插件机制
通过 entry_points(group="dysub.inputs") 自动发现输入源插件:
from dysub_core.inputs.registry import discover_inputs
adapters = discover_inputs()
# {'local': LocalFileAdapter(), 'douyin': DouyinAdapter()}
安装额外插件:
pip install dysub-input-douyin # 抖音链接解析
更多文档
Metadata
Release files for dysub-core 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dysub_core-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for dysub_core-0.1.1-py3-none-any.whl |
Release files / dysub_core-0.1.1-py3-none-any.whl
| Download URL | dysub_core-0.1.1-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0decd45427ae534896b5da7785661973398c8427798b7919cc47f4b35b9237b8
|
|
BLAKE2b-256 checksum How to use checksums |
099be2ebec4b93078798f493e461aa61532d6cf7305b87c3d787cb36c7921795
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for dysub-core 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.