Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
59edc643
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
206
Star
8425
Fork
1598
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
245
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DeepSpeech
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
245
Issue
245
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
59edc643
编写于
8月 15, 2022
作者:
Y
YangZhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add copyrigh
上级
22a5344b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
14 addition
and
15 deletion
+14
-15
paddlespeech/audio/sox_effects/sox_effects.py
paddlespeech/audio/sox_effects/sox_effects.py
+13
-15
tests/unit/audio/backends/sox_io/sox_effect_test.py
tests/unit/audio/backends/sox_io/sox_effect_test.py
+1
-0
未找到文件。
paddlespeech/audio/sox_effects/sox_effects.py
浏览文件 @
59edc643
...
@@ -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
"""
"""
...
...
tests/unit/audio/backends/sox_io/sox_effect_test.py
浏览文件 @
59edc643
#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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录