def make_sound (array):
"""pygame._numpysndarray.make_sound(array): return Sound
Convert an array into a Sound object.
Create a new playable Sound object from an array. The mixer module
must be initialized and the array format must be similar to the mixer
audio format.
"""
# Info is a (freq, format, stereo) tuple
info = pygame.mixer.get_init ()
if not info:
raise pygame.error("Mixer not initialized")
channels = info[2]
shape = array.shape
if channels == 1:
if len (shape) != 1:
raise ValueError("Array must be 1-dimensional for mono mixer")
else:
if len (shape) != 2:
raise ValueError("Array must be 2-dimensional for stereo mixer")
elif shape[1] != channels:
raise ValueError("Array depth must match number of mixer channels")
return mixer.Sound (array)
评论列表
文章目录