Python的winsound模块Beep命令播放两只老虎附简谱说明.py

"""Python的winsond之Beep命令播放两只老虎.py
    这里用C调,4/4,表示以4分音符为一拍,每小节有4拍。
    本程序假设1拍为400毫秒。
   
   freqs列表保存低,中间,高音的频率
    
   duration列表保存时长
   简谱知识:
   全音符为1小节,写法x - - - ,为四拍
   二分音符写法:x - ,为二拍
   四分音符写法:x   ,为一拍
   八分音符写法:x加下划线,为半拍
   
唱名   Do   Re  Mi  Fa    So  La  Si

低音   262  294  330   349    392  440  494    
                       
中音   523  587  659  698    784  880  988  
                         
高音   1046 1175  318  1397  1568  1760  1967

"""

import winsound

freqs = [523,587,659,523,523,587,659,523,659,698,784,659,698,784,784,880,784,698,659,523,784,880,784,698,659,523,523,784,523,523,784,523]
duration= [400,400,400,400,400,400,400,400,400,400,800,400,400,800,300,100,300,100,400,400,300,100,300,100,400,400,400,400,800,400,400,800]
 
for i in range(len(freqs)):
    freq = freqs[i]
    time = duration[i] 
    print(freq,time)
    winsound.Beep(freq, time)



 

下面是《上学歌》频率与延时表

freqs = [523,587,659,523,784,880,880,1046,880,784,880,880,1046,784,880,659,880,784,659,784,659,523,587,659,523]
duration= [200,200,200,200,800,200,200,200,200,800,200,200,400,200,200,400,200,200,200,200,200,200,200,200,800]