I'm trying to play a sine wave using Pygame's sndarray.make_sound
function. However, when I use this array to play it:
np.sin(2 * np.pi * np.arange(44100) * 440 / 44100).astype(np.float32)
where 440
is the frequency and 44100
is the sample rate, a loud, jarring noise plays instead. This works using pyaudio.PyAudio()
, however I need something that doesn't block execution. This happens with square waves, too, however there it just doesn't play anything. I'm using channels=1
for the mixer.pre_init
and mixer.init
functions.
How can I fix this? If it helps, I'm using a Mac. Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…