audioread
audioread copied to clipboard
Support for Seeking to a frame?
Hello, Are there any plans to support seeking to a specific frame?
I'm writing a small app that shows a song's Hz spectograph and, and allows play/pausing of the song along with the spectograph. Play/pause works great, but I'd like a way to reset what frame we're reading from. (That would allow to the user to "stop" and set the time to 0, or click on a spot and seek to that spot.)
I found that the OSX AudioToolbox backend has ExtAudioFileSeek
: https://developer.apple.com/documentation/audiotoolbox/1486821-extaudiofileread?language=objc
And Python aifc
has:
aifc.rewind()
aifc.setpos(pos)
https://docs.python.org/3.6/library/aifc.html
Backends to investigate:
- [x]
rawread.py
/aifc
(hasaifc.setpos
) - [x] ffdec
ffmpeg
(has a seek option on command start. Audioread might have to close & restart the channel on seek?) - [x]
gstdec.py
/Gstreamer
/pygobject
(hasIOChannel.seek
) - [x]
macca.py
/AudioToolbox
(hasExtAudioFileSeek
) - [x]
maddec.py
/MAD
/pymad
(hasseek_time
)
Great idea! This might be hard to support in some backends, like the ffmpeg one, but that shouldn't stop us from adding it to backends where it's easy/possible.
One thing to remember is that we'll want a consistent story for what happens when you seek too far or backwards, if that's disallowed (silent no-op? immediate exception? exception after trying to read post-seek?).
@sampsyo I think I'd vote for an immediate exception, so that users can take their own action. But also, I investigated the backends and I think it's possible to do with all of them.
I'm gonna try adding it to one of the backends and then submit a PR that we can chat about.