Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
7abfad80
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
207
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,发现更多精彩内容 >>
提交
7abfad80
编写于
8月 15, 2022
作者:
Y
YangZhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix typo
上级
59edc643
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
12 addition
and
54 deletion
+12
-54
paddlespeech/audio/sox_effects/sox_effects.py
paddlespeech/audio/sox_effects/sox_effects.py
+0
-48
paddlespeech/audio/src/pybind/sox/io.cpp
paddlespeech/audio/src/pybind/sox/io.cpp
+4
-0
paddlespeech/audio/src/pybind/sox/types.h
paddlespeech/audio/src/pybind/sox/types.h
+1
-1
tests/unit/audio/backends/sox_io/save_test.py
tests/unit/audio/backends/sox_io/save_test.py
+3
-3
tests/unit/common_utils/case_utils.py
tests/unit/common_utils/case_utils.py
+4
-2
未找到文件。
paddlespeech/audio/sox_effects/sox_effects.py
浏览文件 @
7abfad80
...
...
@@ -118,39 +118,6 @@ def apply_effects_tensor(
>>> sample_rate
8000
Example - Torchscript-able transform
>>>
>>> # Use `apply_effects_tensor` in `paddle.nn.Module` and dump it to file,
>>> # then run sox effect via Torchscript runtime.
>>>
>>> class SoxEffectTransform(paddle.nn.Module):
... effects: List[List[str]]
...
... def __init__(self, effects: List[List[str]]):
... super().__init__()
... self.effects = effects
...
... def forward(self, tensor: paddle.Tensor, sample_rate: int):
... return sox_effects.apply_effects_tensor(
... tensor, sample_rate, self.effects)
...
...
>>> # Create transform object
>>> effects = [
... ["lowpass", "-1", "300"], # apply single-pole lowpass filter
... ["rate", "8000"], # change sample rate to 8000
... ]
>>> transform = SoxEffectTensorTransform(effects, input_sample_rate)
>>>
>>> # Dump it to file and load
>>> path = 'sox_effect.zip'
>>> paddle.jit.script(trans).save(path)
>>> transform = paddle.jit.load(path)
>>>
>>>> # Run transform
>>> waveform, input_sample_rate = paddleaudio.load("input.wav")
>>> waveform, sample_rate = transform(waveform, input_sample_rate)
>>> assert sample_rate == 8000
"""
tensor_np
=
tensor
.
numpy
()
ret
=
paddleaudio
.
sox_effects_apply_effects_tensor
(
tensor_np
,
sample_rate
,
effects
,
channels_first
)
...
...
@@ -169,10 +136,6 @@ def apply_effects_file(
)
->
Tuple
[
paddle
.
Tensor
,
int
]:
"""Apply sox effects to the audio file and load the resulting data as Tensor
.. devices:: CPU
.. properties:: TorchScript
Note:
This function works in the way very similar to ``sox`` command, however there are slight
differences. For example, ``sox`` commnad adds certain effects automatically (such as
...
...
@@ -183,17 +146,6 @@ def apply_effects_file(
Args:
path (path-like object or file-like object):
Source of audio data. When the function is not compiled by TorchScript,
(e.g. ``paddle.jit.script``), the following types are accepted:
* ``path-like``: file path
* ``file-like``: Object with ``read(size: int) -> bytes`` method,
which returns byte string of at most ``size`` length.
When the function is compiled by TorchScript, only ``str`` type is allowed.
Note: This argument is intentionally annotated as ``str`` only for
TorchScript compiler compatibility.
effects (List[List[str]]): List of effects.
normalize (bool, optional):
When ``True``, this function always return ``float32``, and sample values are
...
...
paddlespeech/audio/src/pybind/sox/io.cpp
浏览文件 @
7abfad80
...
...
@@ -136,12 +136,16 @@ void save_audio_file(const std::string& path,
const
auto
num_channels
=
tensor
.
shape
(
channels_first
?
0
:
1
);
//TORCH_CHECK(num_channels == 1,
// "amr-nb format only supports single channel audio.");
assert
(
num_channels
==
1
);
}
else
if
(
filetype
==
"htk"
)
{
const
auto
num_channels
=
tensor
.
shape
(
channels_first
?
0
:
1
);
// TORCH_CHECK(num_channels == 1,
// "htk format only supports single channel audio.");
assert
(
num_channels
==
1
);
}
else
if
(
filetype
==
"gsm"
)
{
const
auto
num_channels
=
tensor
.
shape
(
channels_first
?
0
:
1
);
assert
(
num_channels
==
1
);
assert
(
sample_rate
==
8000
);
//TORCH_CHECK(num_channels == 1,
// "gsm format only supports single channel audio.");
//TORCH_CHECK(sample_rate == 8000,
...
...
paddlespeech/audio/src/pybind/sox/types.h
浏览文件 @
7abfad80
...
...
@@ -55,4 +55,4 @@ BitDepth get_bit_depth_from_option(const tl::optional<int64_t> bit_depth);
std
::
string
get_encoding
(
sox_encoding_t
encoding
);
}
// namespace sox_utils
}
// namespace torchaudio
\ No newline at end of file
}
// namespace paddleaudio
\ No newline at end of file
tests/unit/audio/backends/sox_io/save_test.py
浏览文件 @
7abfad80
...
...
@@ -64,7 +64,7 @@ class TestSaveBase(TempDirMixin):
| |
| 2.1. load with scipy | 3.1. Convert to the target
| then save it into the target | format depth with sox
| format with
torch
audio |
| format with
paddle
audio |
v v
target format target format
| |
...
...
@@ -83,7 +83,7 @@ class TestSaveBase(TempDirMixin):
cmp_bit_depth
=
32
src_path
=
self
.
get_temp_path
(
"1.source.wav"
)
tgt_path
=
self
.
get_temp_path
(
f
"2.1.
torch
audio.
{
format
}
"
)
tgt_path
=
self
.
get_temp_path
(
f
"2.1.
paddle
audio.
{
format
}
"
)
tst_path
=
self
.
get_temp_path
(
"2.2.result.wav"
)
sox_path
=
self
.
get_temp_path
(
f
"3.1.sox.
{
format
}
"
)
ref_path
=
self
.
get_temp_path
(
"3.2.ref.wav"
)
...
...
@@ -92,7 +92,7 @@ class TestSaveBase(TempDirMixin):
data
=
get_wav_data
(
src_dtype
,
num_channels
,
normalize
=
False
,
num_frames
=
num_frames
)
save_wav
(
src_path
,
data
,
sample_rate
)
# 2.1. Convert the original wav to target format with
torch
audio
# 2.1. Convert the original wav to target format with
paddle
audio
data
=
load_wav
(
src_path
,
normalize
=
False
)[
0
]
if
test_mode
==
"path"
:
sox_io_backend
.
save
(
...
...
tests/unit/common_utils/case_utils.py
浏览文件 @
7abfad80
...
...
@@ -7,6 +7,8 @@ import tempfile
import
time
import
unittest
#code is from:https://github.com/pytorch/audio/blob/main/test/torchaudio_unittest/common_utils/case_utils.py
import
paddle
from
paddlespeech.audio._internal.module_utils
import
(
is_kaldi_available
,
...
...
@@ -24,9 +26,9 @@ class TempDirMixin:
@
classmethod
def
get_base_temp_dir
(
cls
):
# If
TORCH
AUDIO_TEST_TEMP_DIR is set, use it instead of temporary directory.
# If
PADDLE
AUDIO_TEST_TEMP_DIR is set, use it instead of temporary directory.
# this is handy for debugging.
key
=
"
TORCH
AUDIO_TEST_TEMP_DIR"
key
=
"
PADDLE
AUDIO_TEST_TEMP_DIR"
if
key
in
os
.
environ
:
return
os
.
environ
[
key
]
if
cls
.
temp_dir_
is
None
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录