Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
cc277d09
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,发现更多精彩内容 >>
提交
cc277d09
编写于
7月 01, 2022
作者:
H
Hui Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add backends
上级
4bcecc1c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
144 addition
and
0 deletion
+144
-0
paddlespeech/audio/backends/no_backend.py
paddlespeech/audio/backends/no_backend.py
+27
-0
paddlespeech/audio/backends/sox_io_backend.py
paddlespeech/audio/backends/sox_io_backend.py
+28
-0
paddlespeech/audio/backends/utils.py
paddlespeech/audio/backends/utils.py
+89
-0
未找到文件。
paddlespeech/audio/backends/no_backend.py
0 → 100644
浏览文件 @
cc277d09
from
pathlib
import
Path
from
typing
import
Callable
from
typing
import
Optional
from
typing
import
Tuple
from
typing
import
Union
from
paddle
import
Tensor
def
load
(
filepath
:
Union
[
str
,
Path
],
out
:
Optional
[
Tensor
]
=
None
,
normalization
:
Union
[
bool
,
float
,
Callable
]
=
True
,
channels_first
:
bool
=
True
,
num_frames
:
int
=
0
,
offset
:
int
=
0
,
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
:
raise
RuntimeError
(
"No audio I/O backend is available."
)
def
info
(
filepath
:
str
)
->
None
:
raise
RuntimeError
(
"No audio I/O backend is available."
)
\ No newline at end of file
paddlespeech/audio/backends/sox_io_backend.py
0 → 100644
浏览文件 @
cc277d09
from
pathlib
import
Path
from
typing
import
Callable
from
typing
import
Optional
from
typing
import
Tuple
from
typing
import
Union
from
paddle
import
Tensor
def
load
(
filepath
:
Union
[
str
,
Path
],
out
:
Optional
[
Tensor
]
=
None
,
normalization
:
Union
[
bool
,
float
,
Callable
]
=
True
,
channels_first
:
bool
=
True
,
num_frames
:
int
=
0
,
offset
:
int
=
0
,
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
:
raise
RuntimeError
(
"No audio I/O backend is available."
)
def
info
(
filepath
:
str
)
->
None
:
raise
RuntimeError
(
"No audio I/O backend is available."
)
\ No newline at end of file
paddlespeech/audio/backends/utils.py
0 → 100644
浏览文件 @
cc277d09
"""Defines utilities for switching audio backends"""
import
warnings
from
typing
import
List
from
typing
import
Optional
import
paddlespeech.audio
from
paddlespeech.audio._internal
import
module_utils
as
_mod_utils
from
.
import
no_backend
,
soundfile_backend
,
sox_io_backend
__all__
=
[
"list_audio_backends"
,
"get_audio_backend"
,
"set_audio_backend"
,
]
def
list_audio_backends
()
->
List
[
str
]:
"""List available backends
Returns:
List[str]: The list of available backends.
"""
backends
=
[]
if
_mod_utils
.
is_module_available
(
"soundfile"
):
backends
.
append
(
"soundfile"
)
if
_mod_utils
.
is_sox_available
():
backends
.
append
(
"sox_io"
)
return
backends
def
set_audio_backend
(
backend
:
Optional
[
str
]):
"""Set the backend for I/O operation
Args:
backend (str or None): Name of the backend.
One of ``"sox_io"`` or ``"soundfile"`` based on availability
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
()
}
."
)
if
backend
is
None
:
module
=
no_backend
elif
backend
==
"sox_io"
:
module
=
sox_io_backend
elif
backend
==
"soundfile"
:
module
=
soundfile_backend
else
:
raise
NotImplementedError
(
f
'Unexpected backend "
{
backend
}
"'
)
for
func
in
[
"save"
,
"load"
,
"info"
]:
setattr
(
paddlespeech
.
audio
,
func
,
getattr
(
module
,
func
))
# def _init_audio_backend():
# backends = list_audio_backends()
# if "sox_io" in backends:
# set_audio_backend("sox_io")
# elif "soundfile" in backends:
# set_audio_backend("soundfile")
# else:
# warnings.warn("No audio backend is available.")
# set_audio_backend(None)
def
_init_audio_backend
():
backends
=
list_audio_backends
()
if
"soundfile"
in
backends
:
set_audio_backend
(
"soundfile"
)
elif
"sox_io"
in
backends
:
set_audio_backend
(
"sox_io"
)
else
:
warnings
.
warn
(
"No audio backend is available."
)
set_audio_backend
(
None
)
def
get_audio_backend
()
->
Optional
[
str
]:
"""Get the name of the current backend
Returns:
Optional[str]: The name of the current backend or ``None`` if no backend is assigned.
"""
if
paddlespeech
.
audio
.
load
==
no_backend
.
load
:
return
None
if
paddlespeech
.
audio
.
load
==
sox_io_backend
.
load
:
return
"sox_io"
if
paddlespeech
.
audio
.
load
==
soundfile_backend
.
load
:
return
"soundfile"
raise
ValueError
(
"Unknown backend."
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录