_numpysndarray.py 文件源码

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

项目:AIFun 作者: Plottel 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号