Music Beat Detector
音乐自动打点命令行工具,支持节拍检测和结构检测。
功能
- 节拍检测: 检测 BPM 和每拍时间点
- 结构检测: 检测音乐段落(intro/verse/chorus/bridge/outro)
- 能量分析: 检测能量高峰点
- 静音检测: 检测静音区域
- 多格式支持: MP3, WAV, FLAC, OGG, M4A, AAC, WMA
安装
pip install music-beat-detector
使用
CLI 命令行
# 基本用法(输出到 stdout)
beat-detector ./music-output/jiang02.mp3
# 输出到文件
beat-detector ./music-output/jiang02.mp3 -o ./music-output/yanglin01.json
# 格式化输出
beat-detector ./music-output/jiang02.mp3 -o ./music-output/yanglin01.json --pretty
# 指定帧率
beat-detector ./music-output/jiang02.mp3 --fps 60 -o ./music-output/yanglin01.json
# 调整日志级别
beat-detector ./music-output/jiang02.mp3 --log-level debug
Python API
from beat_detector import analyze
# 基本调用
result = analyze("input.mp3")
# 带参数调用
result = analyze(
"input.mp3",
fps=30, # 帧率
log_level="info", # 日志级别
on_progress=lambda p: print(f"{p}%") # 进度回调
)
# 访问结果
print(f"BPM: {result.meta.bpm}")
print(f"Duration: {result.meta.duration_ms}ms")
print(f"Beats: {len(result.beats)}")
# 导出 JSON
json_str = result.to_json(pretty=True)
result.save("output.json")
输出格式
{
"meta": {
"file": "input.mp3",
"duration_ms": 180000,
"sample_rate": 44100,
"bpm": 120,
"time_signature": "4/4"
},
"beats": [
{"time_ms": 500, "frame": 15, "beat_in_bar": 1},
{"time_ms": 1000, "frame": 30, "beat_in_bar": 2}
],
"structure": {
"segments": [
{
"type": "intro",
"start_ms": 0,
"end_ms": 8000,
"start_frame": 0,
"end_frame": 240,
"confidence": 0.85
}
],
"energy_peaks": [
{"time_ms": 15000, "frame": 450, "intensity": 0.9}
],
"silence_regions": []
}
}
依赖
- librosa - 音频分析
- pydub - 音频格式支持
- numpy - 数值计算
- click - CLI 框架
开发
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
pytest
# 运行测试并生成覆盖率报告
pytest --cov=beat_detector --cov-report=html
许可证
MIT License
Metadata
Release files for music-beat-detector 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| music_beat_detector-0.1.0.tar.gz | 15.3 kB | Without provenance | Details for music_beat_detector-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| music_beat_detector-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for music_beat_detector-0.1.0-py3-none-any.whl |
Total release size: 34.9 kB
Release files / music_beat_detector-0.1.0.tar.gz
| Download URL | music_beat_detector-0.1.0.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94116638ed0050315239169356ffa8bc8e0e75331cc3956a94bc35c6e7a631a8
|
|
BLAKE2b-256 checksum How to use checksums |
44adcd7b79ab828e2a8193ae058e012a7427365a96f63a98d6ae040b651a9242
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / music_beat_detector-0.1.0-py3-none-any.whl
| Download URL | music_beat_detector-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba380e1380fd3d5eed5b1fa0ae15bfecd9e001ea8666745c96d82bc9b07458ce
|
|
BLAKE2b-256 checksum How to use checksums |
011b80324b1723d20a079a0fb34ca36412a3169c013376882f00ce31bd8629c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Security for music-beat-detector 0.1.0
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.