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 warnings
from typing import Optional, Tuple
import torch
......@@ -47,6 +48,14 @@ else:
_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
def info(
filepath: str,
......@@ -94,6 +103,7 @@ def info(
buffer_size = get_buffer_size()
if format == "mp3":
return _fallback_info_fileobj(filepath, format, buffer_size)
warnings.warn(_deprecation_message)
sinfo = torchaudio.lib._torchaudio_sox.get_info_fileobj(filepath, format)
if sinfo is not None:
return AudioMetaData(*sinfo)
......@@ -222,6 +232,7 @@ def load(
format,
buffer_size,
)
warnings.warn(_deprecation_message)
ret = torchaudio.lib._torchaudio_sox.load_audio_fileobj(
filepath, frame_offset, num_frames, normalize, channels_first, format
)
......@@ -402,6 +413,7 @@ def save(
"""
if not torch.jit.is_scripting():
if hasattr(filepath, "write"):
warnings.warn(_deprecation_message)
torchaudio.lib._torchaudio_sox.save_audio_fileobj(
filepath,
src,
......
import os
import warnings
from typing import List, Optional, Tuple
import torch
......@@ -155,6 +156,14 @@ def apply_effects_tensor(
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
def apply_effects_file(
path: str,
......@@ -274,6 +283,7 @@ def apply_effects_file(
"""
if not torch.jit.is_scripting():
if hasattr(path, "read"):
warnings.warn(_deprecation_message)
ret = torchaudio.lib._torchaudio_sox.apply_effects_fileobj(path, effects, normalize, channels_first, format)
if ret is None:
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