Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read markers of .wav file

I would like to use markers in .wav files.

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

How could we read markers of .wav files ?

like image 1000
Basj Avatar asked Nov 15 '13 21:11

Basj


People also ask

Can you metadata WAV files?

FLAC, AIFF and MP3 formats take full advantage of metadata whereas WAV files only allow a little metadata input, so not as helpful for browsing your library. It's important if you want to locate and play music around your home. Network players like our CXN use metadata to browse and play your music.

How do I read a wave file?

Windows and Mac are both capable of opening WAV files. For Windows, if you double-click a WAV file, it will open using Windows Media Player. For Mac, if you double-click a WAV, it will open using iTunes or Quicktime. If you're on a system without these programs installed, then consider third-party software.

What are the numbers in a WAV file?

Traditional 16-bit WAV files store uncompressed audio samples, where each sample is represented by a binary number with 16 digits (binary digit = “bit”). These numbers are “fixed-point”, because they are whole numbers (no decimal point).


1 Answers

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.

like image 113
Basj Avatar answered Sep 24 '22 23:09

Basj