Title, basically. I want to be able to load an audio file (using PyDub, for example) and then display its samples as a waveform. I do not want this waveform to be static, though – the program should allow me to arbitrarily zoom it in and out. In addition, I want to include a functionally basic interaction that will allow me to create a sort of “marker”, which I would be able to place in an arbitrary part of the audio track, reposition it (by dragging it around the time axis) and delete as needed.
Of course, this program requires a bit of additional GUI, so initially I opted for TkInter, since included Canvas seemed like the way to solve the problem of drawing the waveform. There seem to be some issues with this option, though:
-
When the zoom level reaches single samples (e.g. zooming to a few milliseconds of the track), their display should be different than when squeezing multiple seconds/minutes into the view – just like in Audacity. In other words, small number of samples should be drawn in a different way. Therefore, Canvas’
.zoom(...)
function does not seem to be the way to go. -
When zooming a long audio file (an hour long audio, for example) to just a few milliseconds, it’s absolutely not efficient to render the whole remainder of the samples. Therefore, I thought about creating a “static” canvas, which would render just the visible audio portion. With a bit of simple mathematics I managed to implement this and was able to scroll and zoom as I wished. The problem, though, lies in essentially having to redraw the canvas’ every time I move the scrollbar or zoom up or down. From what I’ve read, TkInter’s methods such as
create_line(...)
are not “draw-and-forget” – instead, they somehow “store” these objects, and with this approach are horrendously slow and clog the memory. -
The “redrawing” approach seems to be difficult to combine with the “marker” interaction I mentioned earlier.
I’m stumped. I’d really be grateful for any suggestions on how I could implement this functionality. Is this goal anyhow possible with TkInter, or would you have different library suggestions?
lemo0r is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.