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

Add depreaction warnings to file-like object support in sox_io (#3033)

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

Reviewed By: hwangjeff

Differential Revision: D42966938

Pulled By: mthrok

fbshipit-source-id: 4889735c244690889f02bf57212489ad333389f7
parent b28f9b34
import os import os
import warnings
from typing import Optional, Tuple from typing import Optional, Tuple
import torch import torch
...@@ -47,6 +48,14 @@ else: ...@@ -47,6 +48,14 @@ else:
_fallback_load_fileobj = _fail_load_fileobj _fallback_load_fileobj = _fail_load_fileobj
_deprecation_message = (
"File-like object support in sox_io backend is deprecated, "
"and will be removed in v2.1. "
"See https://github.com/pytorch/audio/issues/2950 for the detail."
"Please migrate to the new dispatcher, or use soundfile backend."
)
@torchaudio._extension.fail_if_no_sox @torchaudio._extension.fail_if_no_sox
def info( def info(
filepath: str, filepath: str,
...@@ -94,6 +103,7 @@ def info( ...@@ -94,6 +103,7 @@ def info(
buffer_size = get_buffer_size() buffer_size = get_buffer_size()
if format == "mp3": if format == "mp3":
return _fallback_info_fileobj(filepath, format, buffer_size) return _fallback_info_fileobj(filepath, format, buffer_size)
warnings.warn(_deprecation_message)
sinfo = torchaudio.lib._torchaudio_sox.get_info_fileobj(filepath, format) sinfo = torchaudio.lib._torchaudio_sox.get_info_fileobj(filepath, format)
if sinfo is not None: if sinfo is not None:
return AudioMetaData(*sinfo) return AudioMetaData(*sinfo)
...@@ -222,6 +232,7 @@ def load( ...@@ -222,6 +232,7 @@ def load(
format, format,
buffer_size, buffer_size,
) )
warnings.warn(_deprecation_message)
ret = torchaudio.lib._torchaudio_sox.load_audio_fileobj( ret = torchaudio.lib._torchaudio_sox.load_audio_fileobj(
filepath, frame_offset, num_frames, normalize, channels_first, format filepath, frame_offset, num_frames, normalize, channels_first, format
) )
...@@ -402,6 +413,7 @@ def save( ...@@ -402,6 +413,7 @@ def save(
""" """
if not torch.jit.is_scripting(): if not torch.jit.is_scripting():
if hasattr(filepath, "write"): if hasattr(filepath, "write"):
warnings.warn(_deprecation_message)
torchaudio.lib._torchaudio_sox.save_audio_fileobj( torchaudio.lib._torchaudio_sox.save_audio_fileobj(
filepath, filepath,
src, src,
......
import os import os
import warnings
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
import torch import torch
...@@ -155,6 +156,14 @@ def apply_effects_tensor( ...@@ -155,6 +156,14 @@ def apply_effects_tensor(
return torch.ops.torchaudio.sox_effects_apply_effects_tensor(tensor, sample_rate, effects, channels_first) return torch.ops.torchaudio.sox_effects_apply_effects_tensor(tensor, sample_rate, effects, channels_first)
_deprecation_message = (
"File-like object support in sox_io backend is deprecated, "
"and will be removed in v2.1. "
"See https://github.com/pytorch/audio/issues/2950 for the detail."
"Please migrate to the new dispatcher, or use soundfile backend."
)
@torchaudio._extension.fail_if_no_sox @torchaudio._extension.fail_if_no_sox
def apply_effects_file( def apply_effects_file(
path: str, path: str,
...@@ -274,6 +283,7 @@ def apply_effects_file( ...@@ -274,6 +283,7 @@ def apply_effects_file(
""" """
if not torch.jit.is_scripting(): if not torch.jit.is_scripting():
if hasattr(path, "read"): if hasattr(path, "read"):
warnings.warn(_deprecation_message)
ret = torchaudio.lib._torchaudio_sox.apply_effects_fileobj(path, effects, normalize, channels_first, format) ret = torchaudio.lib._torchaudio_sox.apply_effects_fileobj(path, effects, normalize, channels_first, format)
if ret is None: if ret is None:
raise RuntimeError("Failed to load audio from {}".format(path)) raise RuntimeError("Failed to load audio from {}".format(path))
......
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