I have an array of raw sound data samples, and I’m trying to make a graphical player that displays the waveform along with the progress of the audio as it plays.
I can plot it easily enough with matplotlib, and I can play it with audiolab, but audiolab appears to have no way to get the “current location” of the playhead.
Are there any modules capable of doing this?
If you know the number of audio frames, and the samplerate, you don’t need to audiolab to tell you the current location, you can compute it.
Sndfile.frames / Sndfile.sampleratewill give you the duration of the file in seconds, you can then use this in conjunction with elapsed time since since sound file start to compute relative current location. To illustrate the principle:To implement this in practice, you could use Python threading, to play the sound file asynchronously, and then compute the current location (as above) in the parent thread. To handle the case where playback fails, wrap your call to
scikits.audiolab.play()in an exception handler, and then usethreading.Eventto pass an event to the parent thread if/when the play() call fails.In the parent thread you would then need to check
event.isSet()accordingly: