I am trying to create a python program that plays a specific note of a harpsichord when a certain key is pressed. I want it to stay responsive so that you can continue to play more notes (like a regular electric piano). However, since the wav files in which notes are stored lasts about 7-10 seconds, I am having some problems. I can press at least 10 keys per second. Thus, in one note, I could use about 100 different wav files at the same time. I tried to use winsound, but it could not play several wav files at once. Then I switched to PyAudio and it works. The only way I found to achieve what I wanted was this:
from msvcrt import getch import pyaudio import wave import multiprocessing as mp
Basically, whenever I want to play a new wav, I need to start a new process that runs the code in the playNote function. As I said, I can have up to 100 of these games at once. Suffice it to say that a hundred instances of the python interpreter that all worked right away almost crashed my computer. I also tried a similar approach with multi-threaded, but had the same problems.
This post shows a way to combine several wav files together so that they can play at the same time, but since my program will not necessarily start sounds at the same time, I'm not sure if this will work. I need an efficient way to play multiple notes at once. Whether it's in the form of another library or even another language, I really don't care.
source share