moglido
moglido

Reputation: 148

SciPy: read marker times and labels in .wav file

I want to access the start and end time points of markers, as well as their labels from a .wav file.

There's a related question with a script by scipy.io.wavfile where the times are returned, but how do I get the marker labels? Thanks!

Upvotes: 1

Views: 1580

Answers (2)

I realize that this question is rather old but I've recently had this problem so a few points may help others. I found two ways to do this.

  1. Export the markers from Adobe Audition as CSV files and then import them into Python using the modules from the standard library.

  2. Wavfile Extended (very useful script created by X-Raym)- Use the 'unsupported' value returned from the read() function.

The read function returns a tuple of various information from the wav file (the markerslist is a list of dictionaries containing the marker information from Adobe Audition). The strings returned by the function are in the form of bytes (b’some text’)

(rate, 
 data, 
 bits, 
 cue, 
 cuelabels, 
 markerslist, 
 info, 
 unsupported) = read("file_with_markers.wav", readmarkers=True, readmarkerlabels=True, readmarkerslist=True)

The ‘unsupported’ value returns a dictionary containing everything stored in the ‘note’, ‘ltxt’ and ‘_PMX’ chunks of the WAV file. The XMP metadata produced by Adobe Audition can be found in the _PMX item, as XML formatted data, and of particular usefulness is the ‘markers’ list (under ‘RDF/Description/Tracks/Bag/li/0/’) which has the full metadata present in Audition (Name, Comment, startTime, Duration).

Conversely the write() function will write a WAV file with a marker list:

Markerlist = {'position': 53318, 'label': b'Speech'}

write('my_marker_test.wav', rate, data, markers=markerslist)

Where ‘rate’ is the sample rate in Hz and data is a 1-D or 2-D numpy array. The markers created in this way are single points (not regions with a start and duration value).

Unfortunately, writing the Adobe XMP metadata to the WAV is unsupported with this module.

Upvotes: 0

PicnicTripper
PicnicTripper

Reputation: 305

Oh I've come across this before! It's an absolute nightmare.

My personal advice, just use the excellent exiftool. This collects all the metadata you could possibly want.

http://www.sno.phy.queensu.ca/~phil/exiftool/

In my case, I created my markers in adobe audition and then used this command in terminal to store the duration times.

exifTool -csv practicefile.wav -TracksMarkersDuration > Durations.csv

exiftool will also let you extract the tags associated with the data. Or, alternatively, just take all the metadata and dump into one nightmarish spreadsheet. The main ones i used were;

-TrackMarkersStartTime -TrackMarkersName

I tried to do it using SciPy and Matlab...I kind of got into it. Basically you'll be reading up a lot of .tiff formats and .XMP metadata format. If you do want to go down that route, you're going to have learn about .XMP (which is basically .XML) Or y'know, use string finding methods to extract that data.

Hope that helps!

Upvotes: 1

Related Questions