pytorch / pytorch/audio

`io.UnsupportedOperation: seek` when using `torchaudio.io.StreamWriter` with a File-like object

Open
#3,918 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
798
Avg merge
58m
Merged PRs (30d)
3

Description

🐛 Describe the bug

In the tutorial for StreamWriter, it is clearly stated that StreamWriter works with File-like object that implements io.RawIOBase.write. However, when I used StreamWriter with the Google Cloud Storage BlobWriter object that implements write but not seek, an error is thrown on calling StreamWriter.close():

from google.cloud.storage import Blob
from torch.io import StreamWriter

blob = Blob(name=..., bucket=...)

with blob.open("wb") as f:
    writer = StreamWriter(dst=f)
    with writer.open():
        ...
self = <torio.io._streaming_media_encoder.StreamingMediaEncoder object at 0x110096190>

    def close(self):
        """Close the output
    
        :py:class:`StreamingMediaEncoder` is also a context manager and therefore supports the
        ``with`` statement.
        It is recommended to use context manager, as the file is closed automatically
        when exiting from ``with`` clause.
    
        See :py:meth:`StreamingMediaEncoder.open` for more detail.
        """
        if self._is_open:
>           self._s.close()
E           io.UnsupportedOperation: seek

.venv/lib/python3.11/site-packages/torio/io/_streaming_media_encoder.py:451: UnsupportedOperation

Clearly seek is called in close(), which causes this error. For now, can I get around this issue by not calling close on the writer object but do call close the blob object?

Versions

google-cloud-storage 3.1.0
torchaudio 2.6.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with torio/io/_streaming_media_encoder.py at the close path shown in the traceback, then compare its behavior with the StreamWriter file-like objects tutorial and reproduce it using Google Cloud Storage BlobWriter. Determine how a write-only object is handled on close and document or correct the behavior, including the safe workaround requested by the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, python
Domain
audio-video-rtc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.