提交 59edc643 编写于 作者: Y YangZhou

add copyrigh

上级 22a5344b
...@@ -63,8 +63,6 @@ def apply_effects_tensor( ...@@ -63,8 +63,6 @@ def apply_effects_tensor(
.. devices:: CPU .. devices:: CPU
.. properties:: TorchScript
Note: Note:
This function only works on CPU Tensors. This function only works on CPU Tensors.
This function works in the way very similar to ``sox`` command, however there are slight This function works in the way very similar to ``sox`` command, however there are slight
...@@ -74,7 +72,7 @@ def apply_effects_tensor( ...@@ -74,7 +72,7 @@ def apply_effects_tensor(
need to give ``rate`` effect with desired sampling rate.). need to give ``rate`` effect with desired sampling rate.).
Args: Args:
tensor (torch.Tensor): Input 2D CPU Tensor. tensor (paddle.Tensor): Input 2D CPU Tensor.
sample_rate (int): Sample rate sample_rate (int): Sample rate
effects (List[List[str]]): List of effects. effects (List[List[str]]): List of effects.
channels_first (bool, optional): Indicates if the input Tensor's dimension is channels_first (bool, optional): Indicates if the input Tensor's dimension is
...@@ -98,9 +96,9 @@ def apply_effects_tensor( ...@@ -98,9 +96,9 @@ def apply_effects_tensor(
>>> # Generate pseudo wave: >>> # Generate pseudo wave:
>>> # normalized, channels first, 2ch, sampling rate 16000, 1 second >>> # normalized, channels first, 2ch, sampling rate 16000, 1 second
>>> sample_rate = 16000 >>> sample_rate = 16000
>>> waveform = 2 * torch.rand([2, sample_rate * 1]) - 1 >>> waveform = 2 * paddle.rand([2, sample_rate * 1]) - 1
>>> waveform.shape >>> waveform.shape
torch.Size([2, 16000]) paddle.Size([2, 16000])
>>> waveform >>> waveform
tensor([[ 0.3138, 0.7620, -0.9019, ..., -0.7495, -0.4935, 0.5442], tensor([[ 0.3138, 0.7620, -0.9019, ..., -0.7495, -0.4935, 0.5442],
[-0.0832, 0.0061, 0.8233, ..., -0.5176, -0.9140, -0.2434]]) [-0.0832, 0.0061, 0.8233, ..., -0.5176, -0.9140, -0.2434]])
...@@ -113,7 +111,7 @@ def apply_effects_tensor( ...@@ -113,7 +111,7 @@ def apply_effects_tensor(
>>> # The new waveform is sampling rate 8000, 1 second. >>> # The new waveform is sampling rate 8000, 1 second.
>>> # normalization and channel order are preserved >>> # normalization and channel order are preserved
>>> waveform.shape >>> waveform.shape
torch.Size([2, 8000]) paddle.Size([2, 8000])
>>> waveform >>> waveform
tensor([[ 0.5054, -0.5518, -0.4800, ..., -0.0076, 0.0096, -0.0110], tensor([[ 0.5054, -0.5518, -0.4800, ..., -0.0076, 0.0096, -0.0110],
[ 0.1331, 0.0436, -0.3783, ..., -0.0035, 0.0012, 0.0008]]) [ 0.1331, 0.0436, -0.3783, ..., -0.0035, 0.0012, 0.0008]])
...@@ -122,17 +120,17 @@ def apply_effects_tensor( ...@@ -122,17 +120,17 @@ def apply_effects_tensor(
Example - Torchscript-able transform Example - Torchscript-able transform
>>> >>>
>>> # Use `apply_effects_tensor` in `torch.nn.Module` and dump it to file, >>> # Use `apply_effects_tensor` in `paddle.nn.Module` and dump it to file,
>>> # then run sox effect via Torchscript runtime. >>> # then run sox effect via Torchscript runtime.
>>> >>>
>>> class SoxEffectTransform(torch.nn.Module): >>> class SoxEffectTransform(paddle.nn.Module):
... effects: List[List[str]] ... effects: List[List[str]]
... ...
... def __init__(self, effects: List[List[str]]): ... def __init__(self, effects: List[List[str]]):
... super().__init__() ... super().__init__()
... self.effects = effects ... self.effects = effects
... ...
... def forward(self, tensor: torch.Tensor, sample_rate: int): ... def forward(self, tensor: paddle.Tensor, sample_rate: int):
... return sox_effects.apply_effects_tensor( ... return sox_effects.apply_effects_tensor(
... tensor, sample_rate, self.effects) ... tensor, sample_rate, self.effects)
... ...
...@@ -146,8 +144,8 @@ def apply_effects_tensor( ...@@ -146,8 +144,8 @@ def apply_effects_tensor(
>>> >>>
>>> # Dump it to file and load >>> # Dump it to file and load
>>> path = 'sox_effect.zip' >>> path = 'sox_effect.zip'
>>> torch.jit.script(trans).save(path) >>> paddle.jit.script(trans).save(path)
>>> transform = torch.jit.load(path) >>> transform = paddle.jit.load(path)
>>> >>>
>>>> # Run transform >>>> # Run transform
>>> waveform, input_sample_rate = paddleaudio.load("input.wav") >>> waveform, input_sample_rate = paddleaudio.load("input.wav")
...@@ -186,7 +184,7 @@ def apply_effects_file( ...@@ -186,7 +184,7 @@ def apply_effects_file(
Args: Args:
path (path-like object or file-like object): path (path-like object or file-like object):
Source of audio data. When the function is not compiled by TorchScript, Source of audio data. When the function is not compiled by TorchScript,
(e.g. ``torch.jit.script``), the following types are accepted: (e.g. ``paddle.jit.script``), the following types are accepted:
* ``path-like``: file path * ``path-like``: file path
* ``file-like``: Object with ``read(size: int) -> bytes`` method, * ``file-like``: Object with ``read(size: int) -> bytes`` method,
...@@ -232,7 +230,7 @@ def apply_effects_file( ...@@ -232,7 +230,7 @@ def apply_effects_file(
>>> >>>
>>> # Check the result >>> # Check the result
>>> waveform.shape >>> waveform.shape
torch.Size([2, 8000]) paddle.Size([2, 8000])
>>> waveform >>> waveform
tensor([[ 5.1151e-03, 1.8073e-02, 2.2188e-02, ..., 1.0431e-07, tensor([[ 5.1151e-03, 1.8073e-02, 2.2188e-02, ..., 1.0431e-07,
-1.4761e-07, 1.8114e-07], -1.4761e-07, 1.8114e-07],
...@@ -244,7 +242,7 @@ def apply_effects_file( ...@@ -244,7 +242,7 @@ def apply_effects_file(
Example - Apply random speed perturbation to dataset Example - Apply random speed perturbation to dataset
>>> >>>
>>> # Load data from file, apply random speed perturbation >>> # Load data from file, apply random speed perturbation
>>> class RandomPerturbationFile(torch.utils.data.Dataset): >>> class RandomPerturbationFile(paddle.utils.data.Dataset):
... \"\"\"Given flist, apply random speed perturbation ... \"\"\"Given flist, apply random speed perturbation
... ...
... Suppose all the input files are at least one second long. ... Suppose all the input files are at least one second long.
...@@ -272,7 +270,7 @@ def apply_effects_file( ...@@ -272,7 +270,7 @@ def apply_effects_file(
... return len(self.flist) ... return len(self.flist)
... ...
>>> dataset = RandomPerturbationFile(file_list, sample_rate=8000) >>> dataset = RandomPerturbationFile(file_list, sample_rate=8000)
>>> loader = torch.utils.data.DataLoader(dataset, batch_size=32) >>> loader = paddle.utils.data.DataLoader(dataset, batch_size=32)
>>> for batch in loader: >>> for batch in loader:
>>> pass >>> pass
""" """
......
#code is from: https://github.com/pytorch/audio/blob/main/test/torchaudio_unittest/sox_effect/sox_effect_test.py
import io import io
import itertools import itertools
import tarfile import tarfile
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册