-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass pre-computed info
to torchaudio.load()
for file-like objects
#1442
Comments
Hi @hbredin Thanks for the pitch. I like the idea but let me give some technical difficulties to achieve this.
Having said that, since I worked on this file-like object support, I also am curious to add streaming capability. # NOTE: This is just an illustration.
stream = torchaudio.load_stream(src, frames_per_chunk, sample_rate, ...)
print(stream.format)
print(stream.bits_per_sample)
for chunk in stream:
... What is your need of streaming? I want to do something about streaming in torchaudio, but at the moment, we do not have an immediate need or request. So if you can fill-in your need and what you would like to achieve in RFC #1072, we can better spec out a new API. |
Thanks a lot for the very detailed answer. I now understand why this is tricky. I just merged a PR in pyannote.audio that simply seeks back to 0 whenever needed. This is kind of ugly (it won't work for unseekable streams) and sub-optimal (because the header will be read again and again) but it does the trick. Regarding streaming, this is something that I would like to support in pyannote.audio eventually (e.g. for live online speaker diarization). The illustrative API above looks like something I could use. Will try to contribute to the mentioned RFC. Closing this issue. Feel free to re-open but I consider my original issue solved (by the aforementioned PR). |
Hi @hbredin I added a new, prototype streaming API, which can support the use case described here. https://pytorch.org/audio/main/tutorials/streaming_api_tutorial.html |
Thanks @mthrok -- will look into it... at some point (but cannot promise any ETA). |
Motivation
Support for file-like object is a great addition to the library. Thanks!
However, if one needs to call both
info
andload
in a row, one must rewind the object between both calls:Withoutp
fp.seek(0)
, we get this error:I presume this happens because
torchaudio.info
consumes the first few bytes of the file to read the header andtorchaudio.load
does not know that...Pitch
Would be nice to be able to provide
torchaudio.load
with the output ofinfo
so that it somehow knows that it has already passed the header section of the file.This would also allow multiple subsequent calls to
torchaudio.load
, which might come handy if we want to process input file as a stream...cc @mogwai
The text was updated successfully, but these errors were encountered: