Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SocialSisterYi/bcut-asr
使用必剪API的语音字幕识别
https://github.com/SocialSisterYi/bcut-asr
Last synced: 3 months ago
JSON representation
使用必剪API的语音字幕识别
- Host: GitHub
- URL: https://github.com/SocialSisterYi/bcut-asr
- Owner: SocialSisterYi
- License: mit
- Created: 2022-10-11T00:54:57.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-28T14:57:30.000Z (6 months ago)
- Last Synced: 2024-06-10T11:37:10.781Z (5 months ago)
- Language: Python
- Size: 48.8 KB
- Stars: 266
- Watchers: 2
- Forks: 38
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- StarryDivineSky - SocialSisterYi/bcut-asr
README
Bcut-ASR
使用必剪 API 进行云端语音字幕识别,支持 CLI 和 module 调用
## ✨Feature
- 可直接上传`flac`, `aac`, `m4a`, `mp3`, `wav`音频格式
- 自动调用 ffmpeg, 实现视频伴音和其他音频格式转码
- 支持`srt`, `json`, `lrc`, `txt`格式字幕输出
- 字幕支持断句和首位时间标记
- 可使用 stdout 输出字幕文本## 🚀Install
首先确保 ffmpeg 已安装,且 PATH 中可以访问,若未安装可以使用如下命令(已安装请无视):
Linux:
```bash
sudo apt install ffmpeg
```Windows:
```powershell
winget install ffmpeg
```本项目暂时未发布 pypi,应使用本地安装,Python 版本应 >= 3.10,需要安装 poetry
```bash
git clone https://github.com/SocialSisterYi/bcut-asr
cd bcut-asr
poetry lock
poetry build -f wheel
pip install dist/bcut_asr-0.0.3-py3-none-any.whl # Example
```## 📃Usage
### CLI Interface
```bash
bcut_asr video.mp4
```或
```bash
bcut_asr video.mp4 subtitle.srt
```或
```bash
bcut_asr video.mp4 -f srt - > subtitle.srt
```长音频指定任务状态轮询间隔(秒),避免接口频繁调用
```bash
bcut_asr video.mp4 -f srt -i 30 - > subtitle.srt
``````
bcut_asr -h
usage: bcut-asr [-h] [-f [{srt,json,lrc,txt}]] [-i [1.0]] input [output]必剪语音识别
positional arguments:
input 输入媒体文件
output 输出字幕文件, 可stdoutoptions:
-h, --help show this help message and exit
-f [{srt,json,lrc,txt}], --format [{srt,json,lrc,txt}]
输出字幕格式
-i [1.0], --interval [1.0]
任务状态轮询间隔(秒)支持输入音频格式: flac, aac, m4a, mp3, wav 支持自动调用ffmpeg提取视频伴音
```### Module
```python
from bcut_asr import BcutASR
from bcut_asr.orm import ResultStateEnumasr = BcutASR('voice.mp3')
asr.upload() # 上传文件
asr.create_task() # 创建任务# 轮询检查结果
while True:
result = asr.result()
# 判断识别成功
if result.state == ResultStateEnum.COMPLETE:
break# 解析字幕内容
subtitle = result.parse()
# 判断是否存在字幕
if subtitle.has_data():
# 输出srt格式
print(subtitle.to_srt())
```输入视频
```python
from bcut_asr import run_everywhere
from argparse import Namespacef = open("file.mp4", "rb")
argg = Namespace(format="srt", interval=30.0, input=f, output=None)
run_everywhere(argg)```