用python自带winsound模块播放上学歌等歌曲

"""上学歌.py
   用C调,2/4,表示以4分音符为一拍,每小节有2拍。
   本程序假设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,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]
 
for i in range(len(freqs)):
    freq = freqs[i]
    time = duration[i] 
    print(freq,time)
    winsound.Beep(freq, time)

"""两只老虎.py"""

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)
"""我爱北京天安门.py"""

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 = [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 ]
 
 
for i in range(len(notes)):
    freq = freqs[notes[i]]
    rate = duration[i]  
    winsound.Beep(freq, rate)
"""一闪一闪亮晶晶.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)


"""数鸭子.py
 

"""

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 = [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 ]
 
 
for i in range(len(notes)):
    freq = freqs[notes[i]]
    rate = duration[i]  
    winsound.Beep(freq, rate)

 

本站所有作品,教程等皆为原创,版权所有。只供个人及单位内部研究使用,对外展示或传播必需经本站同意,且注明来自本站。培训机构等用本站资源培训学生,需经本站授权。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。入住QQ群:225792826 和爱好者共同交流,并且能下载免费提供的Python资源(需提供真实姓名才可入群)
李兴球的博客_Python创意编程技术前沿_pygame » 用python自带winsound模块播放上学歌等歌曲
scratch

学本领,探索更大的世界!

李兴球博客 风火轮编程主页