Skip to content

Commit

Permalink
Fix apply_codec to use named file
Browse files Browse the repository at this point in the history
Follow-up pytorch#3386 The intended change was to use path of temporary
file, instead of file-like object
  • Loading branch information
mthrok committed Jun 1, 2023
1 parent d6dd497 commit 5b71b3c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions torchaudio/_internal/module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def deprecated(direction: str, version: Optional[str] = None, remove: bool = Fal
Args:
direction (str): Migration steps to be given to users.
version (str or int): The version when the object will be removed
remove (bool): If enabled, message about future removal is amended.
"""

def decorator(func):
Expand Down
7 changes: 3 additions & 4 deletions torchaudio/functional/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,12 +1330,11 @@ def apply_codec(
Tensor: Resulting Tensor.
If ``channels_first=True``, it has `(channel, time)` else `(time, channel)`.
"""
with tempfile.TemporaryFile() as f:
with tempfile.NamedTemporaryFile() as f:
torchaudio.backend.sox_io_backend.save(
f, waveform, sample_rate, channels_first, compression, format, encoding, bits_per_sample
f.name, waveform, sample_rate, channels_first, compression, format, encoding, bits_per_sample
)
f.seek(0)
augmented, sr = torchaudio.backend.sox_io_backend.load(f, channels_first=channels_first, format=format)
augmented, sr = torchaudio.backend.sox_io_backend.load(f.name, channels_first=channels_first, format=format)
if sr != sample_rate:
augmented = resample(augmented, sr, sample_rate)
return augmented
Expand Down

0 comments on commit 5b71b3c

Please sign in to comment.