Skip to content

Commit

Permalink
Fix apply_codec to use named file (#3397)
Browse files Browse the repository at this point in the history
Summary:
Follow-up #3386 The intended change was to use path of temporary file, instead of file-like object

Pull Request resolved: #3397

Reviewed By: hwangjeff

Differential Revision: D46346189

Pulled By: mthrok

fbshipit-source-id: 44da799c6587bcb63a118a6313b7299bad742a40
  • Loading branch information
mthrok authored and facebook-github-bot committed Jun 1, 2023
1 parent b99e5f4 commit 1dfac46
Showing 1 changed file with 3 additions and 4 deletions.
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 1dfac46

Please sign in to comment.