wav2sample.py 文件源码

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

项目:gallery 作者: metrasynth 项目源码 文件源码
def load_wav_to_sampler_slot(path, sampler, slot, **kwargs):
    sample = sampler.Sample()
    freq, snd = wavfile.read(str(path))
    if snd.dtype.name == 'int16':
        sample.format = sampler.Format.int16
    elif snd.dtype.name == 'float32':
        sample.format = sampler.Format.float32
    else:
        raise Exception('Not supported')
    if len(snd.shape) == 1:
        size, = snd.shape
        channels = 1
    else:
        size, channels = snd.shape
    sample.rate = freq
    sample.channels = {
        1: m.Sampler.Channels.mono,
        2: m.Sampler.Channels.stereo,
    }[channels]
    sample.data = snd.data.tobytes()
    for key, value in kwargs.items():
        setattr(sample, key, value)
    sampler.samples[slot] = sample
    return sample
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号