Skip to main content

使用必剪API的语音字幕识别

Project description

Bcut-ASR

使用必剪 API 进行云端语音字幕识别,支持 CLI 和 module 调用

✨Feature

  • 可直接上传flac, aac, m4a, mp3, wav音频格式
  • 自动调用 ffmpeg, 实现视频伴音和其他音频格式转码
  • 支持srt, json, lrc, txt格式字幕输出
  • 字幕支持断句和首位时间标记
  • 可使用 stdout 输出字幕文本

🚀Install

首先确保 ffmpeg 已安装,且 PATH 中可以访问,若未安装可以使用如下命令(已安装请无视):

Linux:

sudo apt install ffmpeg

Windows:

winget install ffmpeg

本项目暂时未发布 pypi,应使用本地安装,Python 版本应 >= 3.10,需要安装 poetry

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

bcut_asr video.mp4

bcut_asr video.mp4 subtitle.srt

bcut_asr video.mp4 -f srt - > subtitle.srt

长音频指定任务状态轮询间隔(秒),避免接口频繁调用

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                输出字幕文件, 可stdout

options:
  -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

from bcut_asr import BcutASR
from bcut_asr.orm import ResultStateEnum

asr = 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())

输入视频

from bcut_asr import run_everywhere
from argparse import Namespace


f = open("file.mp4", "rb")
argg = Namespace(format="srt", interval=30.0, input=f, output=None)
run_everywhere(argg)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bcut_asr_branch-0.0.3-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file bcut_asr_branch-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: bcut_asr_branch-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.5 Windows/10

File hashes

Hashes for bcut_asr_branch-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8dbfc55a6ea5abd8bb670297cfcc6211e35117367e883992b204c8e7775a691
MD5 58107500ad76389180f65adb51421f6e
BLAKE2b-256 f11ddd5760d371b9fdc38afc66b9b838e38aef9d1768b27273c91c9671e2df8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page