I get an ogg-encoded audio stream received chunk by chunk via tornado.websocket.WebSocketHandler. My task is to decode it on-the-fly into PCM samples to feed into another algorithm. So the ideal decoding API for me would be something like:
class Decoder():
def push_encoded(self, chunk: bytes):
# TODO: Implement this.
def pop_decoded(self) -> PCMSamples:
# TODO: Implement this.
In other words I need a decoder that internally holds two buffers: the first is to accumulate non yet decoded bytes, the second for already decoded samples.
Alternatively it might be a callback-driven API like:
class Decoder(callback: Callable[[PCMSamples], None]):
def push_encoded(self, chunk: bytes):
# TODO: Implement this.
I tried to use torchaudio.io.StreamReader to implement the API above since I already use this package, but as it turns out it's not that obvious to achieve.
Is there an easy way to implement one of the APIs above using torchaudio or there're other packages more suitable for the task?