项目简介
MusicLang 简称为“音乐语言”,是一个 Python 框架,实现了一种用于音调音乐的新语言。这种语言允许作曲家以简单、浓缩和高级的方式加载、编写、转换和预测象征性音乐。
MusicLang 在内部使用LLM(大型语言模型)来预测乐谱中接下来会发生什么。/!\ 请注意:我们在一个名为 musiclang_predict 的新包中将 AI 与语言本身解耦。如果您想使用 musiclang 的 AI 功能,请安装musiclang_predict包。
这个框架非常适合:
-
快速产生音乐创意。
-
做象征性的音乐预测或修复。
-
创建 MIDI 文件的可解释的富文本表示形式
如何安装
MusicLang 可在 Pypi 上找到:
例子
-
一个在 musiclang 中创建 C 大调和弦并将其保存到 midi 的 hello world 示例:
from musiclang.library import *
# Write a C major chord (First degree of C major scale)
score = (I % I.M)(piano=[s0, s2, s4])
# Store it to midi
score.to_midi('c_major.mid')
-
快速创建、转换和协调主题:
from musiclang.library import *
# Create a cool melody (the beginning of happy birthday, independant of any harmonic context)
melody = s4.ed + s4.s + s5 + s4 + s0.o(1) + s6.h
# Create a simple accompaniment with a cello and a oboe
acc_melody = r + s0.o(-1).q * 3 + s0.o(-1).h
accomp = {'cello__0': acc_melody, 'oboe__0': acc_melody.o(1)}
# Play it in F-major
score = (I % IV.M)(violin__0=melody, **accomp)
# Repeat the score a second time in F-minor and forte
score += (score % I.m).f
# Just to create an anachrusis at the first bar
score = (I % I.M)(violin__0=r.h) + score
# Transform a bit the accompaniment by applying counterpoint rules automatically
score = score.get_counterpoint(fixed_parts=['violin__0'])
# Save it to musicxml
score.to_musicxml('happy_birthday.musicxml', signature=(3, 4), title='Happy birthday !')
# Et voilà !
-
使用在 musiclang 语言上训练的深度学习模型预测乐谱:
http://github.com/MusicLang/musiclang