Commit 54a664b9 authored by Zhaoheng Ni's avatar Zhaoheng Ni Committed by Facebook GitHub Bot
Browse files

Fix type of arguments in torchaudio.io classes (#2913)

Summary:
The `src` or `dst` argument can be `str` or `file-like object`. Setting it to `str` in type annotation will confuse users that it only accepts `str` type.

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

Reviewed By: mthrok

Differential Revision: D41896668

Pulled By: nateanl

fbshipit-source-id: 1446a9f84186a0376cdbe4c61817fae4d5eaaab4
parent 9912e54d
from typing import Dict, Optional, Tuple from typing import BinaryIO, Dict, Optional, Tuple
import torch import torch
import torchaudio import torchaudio
...@@ -105,7 +105,7 @@ def load_audio( ...@@ -105,7 +105,7 @@ def load_audio(
def load_audio_fileobj( def load_audio_fileobj(
src: str, src: BinaryIO,
frame_offset: int = 0, frame_offset: int = 0,
num_frames: int = -1, num_frames: int = -1,
convert: bool = True, convert: bool = True,
......
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from typing import Dict, Iterator, Optional, Tuple from typing import BinaryIO, Dict, Iterator, Optional, Tuple, Union
import torch import torch
import torchaudio import torchaudio
...@@ -350,7 +350,7 @@ class StreamReader: ...@@ -350,7 +350,7 @@ class StreamReader:
def __init__( def __init__(
self, self,
src: str, src: Union[str, BinaryIO, torch.Tensor],
format: Optional[str] = None, format: Optional[str] = None,
option: Optional[Dict[str, str]] = None, option: Optional[Dict[str, str]] = None,
buffer_size: int = 4096, buffer_size: int = 4096,
......
from typing import Dict, Optional from typing import BinaryIO, Dict, Optional, Union
import torch import torch
import torchaudio import torchaudio
...@@ -50,7 +50,7 @@ class StreamWriter: ...@@ -50,7 +50,7 @@ class StreamWriter:
"""Encode and write audio/video streams chunk by chunk """Encode and write audio/video streams chunk by chunk
Args: Args:
dst (str): The destination where the encoded data are written. dst (str or file-like object): The destination where the encoded data are written.
If string-type, it must be a resource indicator that FFmpeg can If string-type, it must be a resource indicator that FFmpeg can
handle. The supported value depends on the FFmpeg found in the system. handle. The supported value depends on the FFmpeg found in the system.
...@@ -100,7 +100,7 @@ class StreamWriter: ...@@ -100,7 +100,7 @@ class StreamWriter:
def __init__( def __init__(
self, self,
dst: str, dst: Union[str, BinaryIO],
format: Optional[str] = None, format: Optional[str] = None,
buffer_size: int = 4096, buffer_size: int = 4096,
): ):
......
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