Pyshnth
音乐生成模块
乐理
- 声音:物体振动产生,振动次数越多,音越高;振动次数越少,音越低
- 可闻:人耳可以听到的声音在每秒16-2000此左右
- 乐音:振动规则产生,听起来高低明显
- 噪音:振动不规则产生,听起来高低不明显
- 音乐:将声音通过艺术形象表达人们的思想感情
- 音阶:do、re、mi、sol、la、(do)
- 调性:C、D、E、F、G、A、B
安装
pip install pysynth
原装示例
import pypsynth
# Example 1: The C major scale
song1 = [
['c',4],['d',4],['e',4],['f',4],['g',4],['a',4],['b',4],['c5',2],['r',1],
['c3',4],['d3',4],['e3',4],['f3',4],['g3',4],['a3',4],['b3',4],['c4',2],['r',1],
['c1*', 1], ['c2*', 1], ['c3*', 1], ['c4*', 1], ['c5*', 1], ['c6*', 1], ['c7*', 1], ['c8*', 1],
]
pysynth.make_wav(song1, fn = "pysynth_scale.wav")
随机轻音乐
import pypsynth
import random
def randsong():
D='cdefgab'
T=range(1, 7)
R = lambda a,b:random.randint(a,b)
M = lambda :f'{D[R(0, len(D))]}{R(1,6)}*'
N = lambda :T[R(0, len(T))]
song = tuple((M(), N()) for i in range(32))
print(song)
pysynth.make_wav(song,fn =r"song.wav")
randsong()