Commit 74dcfba3 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Add special handling to filelike object mp3 (#2478)

Summary:
Loading and querying file-like object is not possible to use the fallback
mechanism introduced in https://github.com/pytorch/audio/issues/2419 because file-like objects are not seekable.

This commit add special case handling to mp3.

For filelike object mp3 input, it was required to pass `format="mp3"`
because libsox did not auto detect the format.

With the transition of mp3 handling from libsox to ffmpeg, the logic
is to let the ffmpeg handle it without waiting for libsox to fail,
if the `format="mp3"`

Note: This is back port of https://github.com/pytorch/audio/issues/2477.

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

Reviewed By: carolineechen

Differential Revision: D37177123

Pulled By: mthrok

fbshipit-source-id: 997eead01c0ad1f04ffa0daa1039302a75f62b63
parent 5e966711
......@@ -84,6 +84,15 @@ def info(
"""
if not torch.jit.is_scripting():
if hasattr(filepath, "read"):
# Special case for Backward compatibility
# v0.11 -> v0.12, mp3 handling is moved to FFmpeg.
# file-like objects are not necessarily fallback-able
# when they are not seekable.
# The previous libsox-based implementation required `format="mp3"`
# because internally libsox does not auto-detect the format.
# For the special BC for mp3, we handle mp3 differently.
if format == "mp3":
return _fallback_info_fileobj(filepath, format)
sinfo = torchaudio._torchaudio.get_info_fileobj(filepath, format)
if sinfo is not None:
return AudioMetaData(*sinfo)
......@@ -194,6 +203,15 @@ def load(
"""
if not torch.jit.is_scripting():
if hasattr(filepath, "read"):
# Special case for Backward compatibility
# v0.11 -> v0.12, mp3 handling is moved to FFmpeg.
# file-like objects are not necessarily fallback-able
# when they are not seekable.
# The previous libsox-based implementation required `format="mp3"`
# because internally libsox does not auto-detect the format.
# For the special BC for mp3, we handle mp3 differently.
if format == "mp3":
return _fallback_load_fileobj(filepath, frame_offset, num_frames, normalize, channels_first, format)
ret = torchaudio._torchaudio.load_audio_fileobj(
filepath, frame_offset, num_frames, normalize, channels_first, format
)
......
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