Commit 1dfac469 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Fix apply_codec to use named file (#3397)

Summary:
Follow-up https://github.com/pytorch/audio/issues/3386 The intended change was to use path of temporary file, instead of file-like object

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

Reviewed By: hwangjeff

Differential Revision: D46346189

Pulled By: mthrok

fbshipit-source-id: 44da799c6587bcb63a118a6313b7299bad742a40
parent b99e5f46
...@@ -1330,12 +1330,11 @@ def apply_codec( ...@@ -1330,12 +1330,11 @@ def apply_codec(
Tensor: Resulting Tensor. Tensor: Resulting Tensor.
If ``channels_first=True``, it has `(channel, time)` else `(time, channel)`. 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( 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.name, channels_first=channels_first, format=format)
augmented, sr = torchaudio.backend.sox_io_backend.load(f, channels_first=channels_first, format=format)
if sr != sample_rate: if sr != sample_rate:
augmented = resample(augmented, sr, sample_rate) augmented = resample(augmented, sr, sample_rate)
return augmented return augmented
......
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