read markers of .wav file

試著忘記壹切 提交于 2019-12-04 06:00:17

Edit: here is an updated version of scipy.io.wavfile that adds many things (24 bit .wav files support for read/write, cue markers, cue markers labels, and some other metadata like pitch (if defined), etc.):

wavfile.py (enhanced)

Feel free to share it!


I finally found a solution (it uses some function of scipy.io.wavfile) :

def readmarkers(file, mmap=False):
    if hasattr(file,'read'):
        fid = file
    else:
        fid = open(file, 'rb')
    fsize = _read_riff_chunk(fid)
    cue = []
    while (fid.tell() < fsize):
        chunk_id = fid.read(4)
        if chunk_id == b'cue ':
            size, numcue = struct.unpack('<ii',fid.read(8))
            for c in range(numcue):
              id, position, datachunkid, chunkstart, blockstart, sampleoffset = struct.unpack('<iiiiii',fid.read(24))
              cue.append(position)
        else:
            _skip_unknown_chunk(fid)
    fid.close()
    return cue

Feel free to add it into Scipy's wavfile.py if someone is interested.

it is in wave.Wave_read modules, called Wave_read.getmarkers() see the docs for detail: http://docs.python.org/2/library/wave.html?highlight=wave#wave.Wave_read.getmarkers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!