Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions torchaudio/backend/soundfile_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings
from typing import Optional, Tuple

import torch
Expand Down Expand Up @@ -34,8 +35,26 @@ def load(filepath: str,
offset: int = 0,
signalinfo: SignalInfo = None,
encodinginfo: EncodingInfo = None,
filetype: Optional[str] = None) -> Tuple[Tensor, int]:
filetype: Optional[str] = None,
*,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the *?

normalize: bool = True,
frame_offset: int = 0) -> Tuple[Tensor, int]:
r"""See torchaudio.load"""
warnings.warn(
'The return type of `load` function in "soundfile" backend is going to be changed in 0.8.0. '
'Please refer to https://github.com/pytorch/audio/issues/903 for the detail.'
)
Comment on lines +43 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine to me. next best thing to creating a new backend?


if not normalization:
warnings.warn(
'"normalization" argument is deprecated and removed in 0.8.0. Please use "normalize".')
elif not normalize:
normalization = normalize
if offset != 0:
warnings.warn(
'"offset" argument is deprecated and removed in 0.8.0. Please use "frame_offset".')
elif frame_offset != 0:
offset = frame_offset
Comment on lines +56 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can always be done?


assert out is None
assert normalization
Expand Down Expand Up @@ -82,9 +101,29 @@ def load_wav(filepath, **kwargs):

@_mod_utils.requires_module('soundfile')
@common._impl_save
def save(filepath: str, src: Tensor, sample_rate: int, precision: int = 16, channels_first: bool = True) -> None:
def save(
filepath: str,
src: Tensor,
sample_rate: int,
precision: int = 16,
channels_first: bool = True,
*,
compression: Optional[float] = None,
) -> None:
r"""See torchaudio.save"""

if precision:
warnings.warn(
'"precision" argument is depricated and removed in 0.8.0. In 0.8.0, '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: deprecated

'convert the input Tensor to dtype of desired precision.'
)

if compression is not None:
warnings.warn(
'"soundfile" backend\'s `save` function does not support changing compression level. '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an issue that gives more detail for this?

'`compression` argument is silently ignore.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: silently ignored

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this parameter be removed?

)

ch_idx, len_idx = (0, 1) if channels_first else (1, 0)

# check if save directory exists
Expand Down
3 changes: 3 additions & 0 deletions torchaudio/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def set_audio_backend(backend: Optional[str]):
elif backend == 'sox_io':
module = sox_io_backend
elif backend == 'soundfile':
warnings.warn(
'"soundfile" backend is planned to change the function signatures in 0.8.0. '
'Please refer to https://github.com/pytorch/audio/issues/903 for the migration step.')
Comment on lines +61 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the real issue behind this particular comment is the return type? then it could be specialized to return type?

Copy link
Contributor

@vincentqb vincentqb Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about a local parameter that controls the return type in the load/save function?

module = soundfile_backend
else:
raise NotImplementedError(f'Unexpected backend "{backend}"')
Expand Down