GA-Music-Program.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:genetic-algorithm-music 作者: suhas-r 项目源码 文件源码
def playMusic(song, rhythm):
    pyglet.options['audio'] = ('openal', 'silent')
    switcherNotes = {
#pyglet.media.load("A.wav").play()
        1: "A.wav", #A
        2: "A#.wav",#A#
        3: "B.wav",#B"
        4: "C.wav",#C"
        5: "C#.wav",#C#"
        6: "D.wav",#D"
        7: "D#.wav",#D#"
        8: "E.wav",#E"
        9: "F.wav",#F"
        10: "F#.wav",#F#"
        11: "G.wav",#G"
        12: "G#.wav" #G#"
    }
    switcherRhythms = {
        0: 0.75,
        1: 0.0625,
        2: 0.125,
        3: 0.25,
        4: 1.5,
        5: 0.5,
        6: 3,
        7: 1
    }
    #player = pyglet.media.Player()
    for i in range(0, len(song)):
        totalTime = 0
        while(totalTime < switcherRhythms[rhythm[i]]):
            if song[i] != 0:
                pyglet.media.load(switcherNotes[song[i]], streaming=False).play()
            #time.sleep(switcherRhythms[rhythm[i]]*.5)
            time.sleep(.0625*1.5)
            totalTime += .0625
#pyglet.media.load("A.wav").play()
#notes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号