Playing a Lot of Sounds at Once

前端 未结 2 1777
感动是毒
感动是毒 2020-12-19 00:00

I am attempting to create a program in python that plays a particular harpsichord note when a certain key is pressed. I want it to remain responsive so you can continue to

2条回答
  •  心在旅途
    2020-12-19 00:31

    I checked out pygame like J.F Sebastian suggested. It ended up being exactly what I needed. I used pygame.mixer.Sound() in conjunction with pygame.mixer.set_num_channels(). Here's what I came up with.

    import pygame as pg
    import time
    
    pg.mixer.init()
    pg.init()
    
    a1Note = pg.mixer.Sound("F:\Project Harpsichord\The wavs\A1.wav")
    a2Note = pg.mixer.Sound("F:\Project Harpsichord\The wavs\A0.wav")
    
    pg.mixer.set_num_channels(50)
    
    for i in range(25):
        a1Note.play()
        time.sleep(0.3)
        a2Note.play()
        time.sleep(0.3)
    

提交回复
热议问题