Skip to content

Commit 1dfac46

Browse files
mthrokfacebook-github-bot
authored andcommitted
Fix apply_codec to use named file (#3397)
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
1 parent b99e5f4 commit 1dfac46

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

torchaudio/functional/functional.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,12 +1330,11 @@ def apply_codec(
13301330
Tensor: Resulting Tensor.
13311331
If ``channels_first=True``, it has `(channel, time)` else `(time, channel)`.
13321332
"""
1333-
with tempfile.TemporaryFile() as f:
1333+
with tempfile.NamedTemporaryFile() as f:
13341334
torchaudio.backend.sox_io_backend.save(
1335-
f, waveform, sample_rate, channels_first, compression, format, encoding, bits_per_sample
1335+
f.name, waveform, sample_rate, channels_first, compression, format, encoding, bits_per_sample
13361336
)
1337-
f.seek(0)
1338-
augmented, sr = torchaudio.backend.sox_io_backend.load(f, channels_first=channels_first, format=format)
1337+
augmented, sr = torchaudio.backend.sox_io_backend.load(f.name, channels_first=channels_first, format=format)
13391338
if sr != sample_rate:
13401339
augmented = resample(augmented, sr, sample_rate)
13411340
return augmented

0 commit comments

Comments
 (0)