Commit 12e8cb97 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Tweak docs around IO (#3064)

Summary:
* Mention context manager in StreamWriter
* Add FFmpeg as optional dependency

Pull Request resolved: https://github.com/pytorch/audio/pull/3064

Reviewed By: hwangjeff

Differential Revision: D43307818

Pulled By: mthrok

fbshipit-source-id: 86339d973aba85e090f520e08af65b5d736e3d18
parent b0af1406
...@@ -28,6 +28,11 @@ Dependencies ...@@ -28,6 +28,11 @@ Dependencies
Optional Dependencies Optional Dependencies
~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
* `FFmpeg <https://ffmpeg.org>`_.
Required to use :py:mod:`torchaudio.io` module.
TorchAudio official binary distributions are compatible with FFmpeg 4.1 to 4.4.
If you need to use FFmpeg 5, please build TorchAudio from source.
* `sentencepiece <https://pypi.org/project/sentencepiece/>`_ * `sentencepiece <https://pypi.org/project/sentencepiece/>`_
......
...@@ -221,9 +221,16 @@ class StreamWriter: ...@@ -221,9 +221,16 @@ class StreamWriter:
"""[debug] Print the registered stream information to stdout.""" """[debug] Print the registered stream information to stdout."""
self._s.dump_format(i) self._s.dump_format(i)
def open(self, option: Optional[Dict[str, str]] = None): def open(self, option: Optional[Dict[str, str]] = None) -> "StreamWriter":
"""Open the output file / device and write the header. """Open the output file / device and write the header.
:py:class:`StreamWriter` is also a context manager and therefore supports the
``with`` statement.
This method returns the instance on which the method is called (i.e. `self`),
so that it can be used in `with` statement.
It is recommended to use context manager, as the file is closed automatically
when exiting from ``with`` clause.
Args: Args:
option (dict or None, optional): Private options for protocol, device and muxer. See example. option (dict or None, optional): Private options for protocol, device and muxer. See example.
...@@ -256,7 +263,15 @@ class StreamWriter: ...@@ -256,7 +263,15 @@ class StreamWriter:
return self return self
def close(self): def close(self):
"""Close the output""" """Close the output
:py:class:`StreamWriter` 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:`StreamWriter.open` for more detail.
"""
if self._is_open: if self._is_open:
self._s.close() self._s.close()
self._is_open = False self._is_open = False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment