Files
skills/musicXML-ocr/references/verovio_preview.md
T
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

71 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Verovio 渲染预览
## 安装
```bash
pip install verovio
```
## 渲染 MusicXML 为图片
```python
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")
```
## 命令行工具
```bash
# 安装命令行工具
pip install verovio[commandline]
# 转换
vrv tool -o output.png input.musicxml -r 300
```
## 在 Jupyter 中预览
```python
from IPython.display import SVG, display
toolkit = verovio.toolkit()
toolkit.loadFile("score.musicxml")
svg = toolkit.renderToSVG()
display(SVG(svg))
```
## 调整页面布局
```python
toolkit.setOption("pageWidth", 2100) # 页面宽度(tenths
toolkit.setOption("pageHeight", 2970) # 页面高度
toolkit.setOption("scale", 50) # 缩放比例
toolkit.setOption("spacingSystem", 50) # 五线间距
```
## 获取 MIDI
```python
toolkit.loadFile("score.musicxml")
midi = toolkit.renderToMIDI()
with open("output.mid", "wb") as f:
f.write(midi)
```