Read .wav file markers

I would like to use markers in .wav files.

The aifc module seems to be supported with getmarkers() : http://docs.python.org/2/library/aifc.html#aifc.aifc.getmarkers (for .aiff files), but not for the wave module ( http: // docs.python.org/2/library/wave.html?highlight=wave#wave.Wave_read.getmarkers ).

How could we read markers of .wav files?

+6
source share
2 answers

Edit : here is an updated version of scipy.io.wavfile that adds a lot of things (support for 24-bit .wav files for reading / writing, tag labels, tag label tags and some other metadata like step (if defined), etc. .):

wavfile.py (improved)

Feel free to share it!


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

 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 to Scipy wavfile.py if anyone is interested.

+3
source

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

-1
source

Source: https://habr.com/ru/post/958175/


All Articles