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

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

"""上学歌.py
用C调，2/4，表示以4分音符为一拍，每小节有2拍。
本程序假设1拍为400毫秒。

freqs列表保存低，中间，高音的频率

duration列表保存时长

简谱知识：
全音符为1小节，写法x - - - ，为四拍
二分音符写法：x - ，为二拍
四分音符写法：x   ,为一拍
八分音符写法：x加下划线，为半拍

"""

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)