读取.wav文件的标记

Bas*_*asj 7 python audio wav markers

我想在.wav文件中使用标记.

它似乎得到以下aifc模块的支持getmarkers():http://docs.python.org/2/library/aifc.html#aifc.aifc.getmarkers(对于.aiff文件),但不支持wave模块(http:// docs. python.org/2/library/wave.html?highlight=wave#wave.Wave_read.getmarkers).

我们怎样才能读取 .wav文件的标记

Bas*_*asj 5

编辑:这是一个更新版本,scipy.io.wavfile添加了许多内容(24 位 .wav 文件支持读/写、提示标记、提示标记标签以及一些其他元数据,如音高(如果定义)等):

wavfile.py(增强)

欢迎分享!


我终于找到了一个解决方案(它使用了 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
Run Code Online (Sandbox Code Playgroud)

wavfile.py如果有人感兴趣,请随意将其添加到 Scipy 中。