Files
hmo 04db423416 Initial commit: skills library
- 70 skills with code and documentation
- Add .gitignore (ignore __pycache__, output/, temp/, venv/)
- Clean up test intermediates and caches
2026-04-26 19:27:40 +08:00

1.2 KiB
Raw Permalink Blame History

Verovio 渲染预览

安装

pip install verovio

渲染 MusicXML 为图片

import verovio

toolkit = verovio.toolkit()

# 加载 MusicXML
toolkit.loadFile("score.musicxml")

# 渲染为 SVG
svg = toolkit.renderToSVG()

# 保存 SVG
with open("output.svg", "w") as f:
    f.write(svg)

# 渲染为 PNG
toolkit.renderToPNG("output.png", 300)  # 300 DPI

# 渲染为 PDF
toolkit.renderToPDF("output.pdf")

命令行工具

# 安装命令行工具
pip install verovio[commandline]

# 转换
vrv tool -o output.png input.musicxml -r 300

在 Jupyter 中预览

from IPython.display import SVG, display

toolkit = verovio.toolkit()
toolkit.loadFile("score.musicxml")
svg = toolkit.renderToSVG()
display(SVG(svg))

调整页面布局

toolkit.setOption("pageWidth", 2100)   # 页面宽度(tenths
toolkit.setOption("pageHeight", 2970)  # 页面高度
toolkit.setOption("scale", 50)         # 缩放比例
toolkit.setOption("spacingSystem", 50) # 五线间距

获取 MIDI

toolkit.loadFile("score.musicxml")
midi = toolkit.renderToMIDI()
with open("output.mid", "wb") as f:
    f.write(midi)