pull/2157/head
Hui Zhang 3 years ago
parent a7181bcde8
commit 84e5bc0382

@ -5,6 +5,7 @@ from typing import Optional
#code is from https://github.com/pytorch/audio/blob/main/torchaudio/_internal/module_utils.py
def is_module_available(*modules: str) -> bool:
r"""Returns if a top-level module with :attr:`name` exists *without**
importing it. This is generally safer than try-catch block around a

@ -8,6 +8,7 @@ from paddle import Tensor
#code is from: https://github.com/pytorch/audio/blob/main/torchaudio/backend/no_backend.py
def load(
filepath: Union[str, Path],
out: Optional[Tensor]=None,
@ -15,12 +16,15 @@ def load(
channels_first: bool=True,
num_frames: int=0,
offset: int=0,
filetype: Optional[str] = None,
) -> Tuple[Tensor, int]:
filetype: Optional[str]=None, ) -> Tuple[Tensor, int]:
raise RuntimeError("No audio I/O backend is available.")
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) -> None:
raise RuntimeError("No audio I/O backend is available.")

@ -1,4 +1,3 @@
from pathlib import Path
from typing import Callable
from typing import Optional
@ -9,6 +8,7 @@ from paddle import Tensor
#https://github.com/pytorch/audio/blob/main/torchaudio/backend/sox_io_backend.py
def load(
filepath: Union[str, Path],
out: Optional[Tensor]=None,
@ -16,12 +16,15 @@ def load(
channels_first: bool=True,
num_frames: int=0,
offset: int=0,
filetype: Optional[str] = None,
) -> Tuple[Tensor, int]:
filetype: Optional[str]=None, ) -> Tuple[Tensor, int]:
raise RuntimeError("No audio I/O backend is available.")
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) -> None:
raise RuntimeError("No audio I/O backend is available.")

@ -40,7 +40,8 @@ def set_audio_backend(backend: Optional[str]):
of the system. If ``None`` is provided the current backend is unassigned.
"""
if backend is not None and backend not in list_audio_backends():
raise RuntimeError(f'Backend "{backend}" is not one of ' f"available backends: {list_audio_backends()}.")
raise RuntimeError(f'Backend "{backend}" is not one of '
f"available backends: {list_audio_backends()}.")
if backend is None:
module = no_backend
@ -76,6 +77,7 @@ def _init_audio_backend():
warnings.warn("No audio backend is available.")
set_audio_backend(None)
def get_audio_backend() -> Optional[str]:
"""Get the name of the current backend

@ -27,7 +27,8 @@ __all__ = [
@module_utils.requires_kaldi()
def fbank(wav,
def fbank(
wav,
samp_freq: int=16000,
frame_shift_ms: float=10.0,
frame_length_ms: float=25.0,
@ -88,6 +89,7 @@ def fbank(wav,
feat = ComputeFbank(frame_opts, mel_opts, fbank_opts, wav)
return feat
@module_utils.requires_kaldi()
def pitch(wav,
samp_freq: int=16000,

Loading…
Cancel
Save