Python播放MIDI用Beep命令_一闪一闪亮晶晶.py

"""一闪一闪亮晶晶.py
   C大调,2/4                     四分音符为一拍,每小节两拍。
   freqs列表保存低,中间,高音的频率
   notes列表保存的是freqs中一些频率的索引号
   duration列表保存时长
   简谱知识:
   全音符为1小节,写法x - - - ,为四拍
   二分音符写法:x - ,为二拍
   四分音符写法:x   ,为一拍
   八分音符写法:x加下划线,为半拍
   

"""

import winsound

 
"           低音                         中音                        高音 "
"            1   2   3   4   5   6    7  1   2   3   4   5   6   7    1     2     3      4     5    6     7"
freqs = [37,262,294,330,349,392,440,494,523,587,659,698,784,880,988, 1046, 1175, 1318, 1397, 1568, 1760,1967]
"                                        8   9   10  11  12  13  14 "
"                                        C   D    E   F   G            调"

notes = [8,8,12,12,13,13,12,11,11,10,10,9,9,8,12,12,11,11,10,10,9,12,12,11,11,10,10,9,8,8,12,12,13,13,12,11,11,10,10,9,9,8]  #保存的是freqs列表索引号
duration = [4,4,4,4,4,4,8,4,4,4,4,4,4,8,4,4,4,4,4,4,8,4,4,4,4,4,4,8,4,4,4,4,4,4,8,4,4,4,4,4,4,8]
duration = [ d * 125 for d in duration ]
 
 
for i in range(len(notes)):
    freq = freqs[notes[i]]
    rate = duration[i]  
    winsound.Beep(freq, rate)



 

《数鸭子》频率与延时表:

notes = [10,8,10,10,8,10,10,12,13,12,0,13,13,13,12,11,11,11,9,10,9,8,9,0,10,8,0,10,8,0,10,10,12,13,13,0,15,12,12,13,10,9,8,9,10,12,15,12,12,13,10,9,8,9,10,8] #保存的是freqs列表索引号
duration = [4,4,2,2,4,2,2,2,2,4,4,2,2,2,2,2,2,4,2,2,2,2,4,4,4,2,2,4,2,2,2,2,2,2,4,4,4,2,2,4,4,2,2,2,2,8,4,2,2,4,4,2,2,2,2,8]
duration = [ d * 125 for d in duration ]

 

《我爱北京天安门》频率与延时表:

notes = [12,15,12,11,10,9,8,8,8,9,10,10,8,10,11,12,12,15,12,11,10,12,9,11,10,9,13,12,9,0,8] #保存的是freqs列表索引号
duration = [2,1,2,2,2,2,4,2,2,2,2,2,2,2,2,16,2,1,2,2,2,2,4,2,1,2,2,4,2,2,12]
duration = [ d * 125 for d in duration ]