Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e1eb52e1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e1eb52e1
编写于
8月 15, 2023
作者:
L
LoneRanger
提交者:
GitHub
8月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[xdoctest] reformat example code with google style in No.12-No.15 (#56210)
* fix sample codes * fix bug * Update tess.py
上级
702efe0f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
141 addition
and
124 deletion
+141
-124
python/paddle/audio/backends/init_backend.py
python/paddle/audio/backends/init_backend.py
+57
-51
python/paddle/audio/backends/wave_backend.py
python/paddle/audio/backends/wave_backend.py
+35
-35
python/paddle/audio/datasets/esc50.py
python/paddle/audio/datasets/esc50.py
+30
-19
python/paddle/audio/datasets/tess.py
python/paddle/audio/datasets/tess.py
+19
-19
未找到文件。
python/paddle/audio/backends/init_backend.py
浏览文件 @
e1eb52e1
...
@@ -43,25 +43,27 @@ def list_available_backends() -> List[str]:
...
@@ -43,25 +43,27 @@ def list_available_backends() -> List[str]:
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
sample_rate = 16000
>>> sample_rate = 16000
wav_duration = 0.5
>>> wav_duration = 0.5
num_channels = 1
>>> num_channels = 1
num_frames = sample_rate * wav_duration
>>> num_frames = sample_rate * wav_duration
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
>>> wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
waveform = wav_data.tile([num_channels, 1])
>>> waveform = wav_data.tile([num_channels, 1])
wav_path = "./test.wav"
>>> wav_path = "./test.wav"
current_backend = paddle.audio.backends.get_current_backend()
>>> current_backend = paddle.audio.backends.get_current_backend()
print(current_backend) # wave_backend, the default backend.
>>> print(current_backend)
backends = paddle.audio.backends.list_available_backends()
wave_backend
# default backends is ['wave_backend']
# backends is ['wave_backend', 'soundfile'], if have installed paddleaudio >= 1.0.2
>>> backends = paddle.audio.backends.list_available_backends()
if 'soundfile' in backends:
>>> # default backends is ['wave_backend']
paddle.audio.backends.set_backend('soundfile')
>>> # backends is ['wave_backend', 'soundfile'], if have installed paddleaudio >= 1.0.2
>>> if 'soundfile' in backends:
paddle.audio.save(wav_path, waveform, sample_rate)
... paddle.audio.backends.set_backend('soundfile')
...
>>> paddle.audio.save(wav_path, waveform, sample_rate)
"""
"""
backends
=
[]
backends
=
[]
...
@@ -100,26 +102,28 @@ def get_current_backend() -> str:
...
@@ -100,26 +102,28 @@ def get_current_backend() -> str:
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
sample_rate = 16000
>>>
sample_rate = 16000
wav_duration = 0.5
>>>
wav_duration = 0.5
num_channels = 1
>>>
num_channels = 1
num_frames = sample_rate * wav_duration
>>>
num_frames = sample_rate * wav_duration
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
>>>
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
waveform = wav_data.tile([num_channels, 1])
>>>
waveform = wav_data.tile([num_channels, 1])
wav_path = "./test.wav"
>>>
wav_path = "./test.wav"
current_backend = paddle.audio.backends.get_current_backend()
>>> current_backend = paddle.audio.backends.get_current_backend()
print(current_backend) # wave_backend, the default backend.
>>> print(current_backend)
backends = paddle.audio.backends.list_available_backends()
wave_backend
# default backends is ['wave_backend']
# backends is ['wave_backend', 'soundfile'], if have installed paddleaudio >= 1.0.2
if 'soundfile' in backends:
>>> backends = paddle.audio.backends.list_available_backends()
paddle.audio.backends.set_backend('soundfile')
>>> # default backends is ['wave_backend']
>>> # backends is ['wave_backend', 'soundfile'], if have installed paddleaudio >= 1.0.2
paddle.audio.save(wav_path, waveform, sample_rate)
>>> if 'soundfile' in backends:
... paddle.audio.backends.set_backend('soundfile')
...
>>> paddle.audio.save(wav_path, waveform, sample_rate)
"""
"""
current_backend
=
None
current_backend
=
None
...
@@ -144,26 +148,28 @@ def set_backend(backend_name: str):
...
@@ -144,26 +148,28 @@ def set_backend(backend_name: str):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
sample_rate = 16000
>>>
sample_rate = 16000
wav_duration = 0.5
>>>
wav_duration = 0.5
num_channels = 1
>>>
num_channels = 1
num_frames = sample_rate * wav_duration
>>>
num_frames = sample_rate * wav_duration
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
>>>
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
waveform = wav_data.tile([num_channels, 1])
>>>
waveform = wav_data.tile([num_channels, 1])
wav_path = "./test.wav"
>>>
wav_path = "./test.wav"
current_backend = paddle.audio.backends.get_current_backend()
>>> current_backend = paddle.audio.backends.get_current_backend()
print(current_backend) # wave_backend, the default backend.
>>> print(current_backend)
backends = paddle.audio.backends.list_available_backends()
wave_backend
# default backends is ['wave_backend']
# backends is ['wave_backend', 'soundfile'], if have installed paddleaudio >= 1.0.2
if 'soundfile' in backends:
>>> backends = paddle.audio.backends.list_available_backends()
paddle.audio.backends.set_backend('soundfile')
>>> # default backends is ['wave_backend']
>>> # backends is ['wave_backend', 'soundfile'], if have installed paddleaudio >= 1.0.2
paddle.audio.save(wav_path, waveform, sample_rate)
>>> if 'soundfile' in backends:
... paddle.audio.backends.set_backend('soundfile')
...
>>> paddle.audio.save(wav_path, waveform, sample_rate)
"""
"""
if
backend_name
not
in
list_available_backends
():
if
backend_name
not
in
list_available_backends
():
...
...
python/paddle/audio/backends/wave_backend.py
浏览文件 @
e1eb52e1
...
@@ -46,20 +46,20 @@ def info(filepath: str) -> AudioInfo:
...
@@ -46,20 +46,20 @@ def info(filepath: str) -> AudioInfo:
Example:
Example:
.. code-block:: python
.. code-block:: python
import os
>>>
import os
import paddle
>>>
import paddle
sample_rate = 16000
>>>
sample_rate = 16000
wav_duration = 0.5
>>>
wav_duration = 0.5
num_channels = 1
>>>
num_channels = 1
num_frames = sample_rate * wav_duration
>>>
num_frames = sample_rate * wav_duration
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
>>>
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
waveform = wav_data.tile([num_channels, 1])
>>>
waveform = wav_data.tile([num_channels, 1])
base_dir = os.getcwd()
>>>
base_dir = os.getcwd()
filepath = os.path.join(base_dir, "test.wav")
>>>
filepath = os.path.join(base_dir, "test.wav")
paddle.audio.save(filepath, waveform, sample_rate)
>>>
paddle.audio.save(filepath, waveform, sample_rate)
wav_info = paddle.audio.info(filepath)
>>>
wav_info = paddle.audio.info(filepath)
"""
"""
if
hasattr
(
filepath
,
'read'
):
if
hasattr
(
filepath
,
'read'
):
...
@@ -111,20 +111,20 @@ def load(
...
@@ -111,20 +111,20 @@ def load(
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import os
>>>
import os
import paddle
>>>
import paddle
sample_rate = 16000
>>>
sample_rate = 16000
wav_duration = 0.5
>>>
wav_duration = 0.5
num_channels = 1
>>>
num_channels = 1
num_frames = sample_rate * wav_duration
>>>
num_frames = sample_rate * wav_duration
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
>>>
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
waveform = wav_data.tile([num_channels, 1])
>>>
waveform = wav_data.tile([num_channels, 1])
base_dir = os.getcwd()
>>>
base_dir = os.getcwd()
filepath = os.path.join(base_dir, "test.wav")
>>>
filepath = os.path.join(base_dir, "test.wav")
paddle.audio.save(filepath, waveform, sample_rate)
>>>
paddle.audio.save(filepath, waveform, sample_rate)
wav_data_read, sr = paddle.audio.load(filepath)
>>>
wav_data_read, sr = paddle.audio.load(filepath)
"""
"""
if
hasattr
(
filepath
,
'read'
):
if
hasattr
(
filepath
,
'read'
):
file_obj
=
filepath
file_obj
=
filepath
...
@@ -192,17 +192,17 @@ def save(
...
@@ -192,17 +192,17 @@ def save(
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
sample_rate = 16000
>>>
sample_rate = 16000
wav_duration = 0.5
>>>
wav_duration = 0.5
num_channels = 1
>>>
num_channels = 1
num_frames = sample_rate * wav_duration
>>>
num_frames = sample_rate * wav_duration
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
>>>
wav_data = paddle.linspace(-1.0, 1.0, num_frames) * 0.1
waveform = wav_data.tile([num_channels, 1])
>>>
waveform = wav_data.tile([num_channels, 1])
filepath = "./test.wav"
>>>
filepath = "./test.wav"
paddle.audio.save(filepath, waveform, sample_rate)
>>>
paddle.audio.save(filepath, waveform, sample_rate)
"""
"""
assert
src
.
ndim
==
2
,
"Expected 2D tensor"
assert
src
.
ndim
==
2
,
"Expected 2D tensor"
...
...
python/paddle/audio/datasets/esc50.py
浏览文件 @
e1eb52e1
...
@@ -47,25 +47,36 @@ class ESC50(AudioClassificationDataset):
...
@@ -47,25 +47,36 @@ class ESC50(AudioClassificationDataset):
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
mode = 'dev'
>>> mode = 'dev'
esc50_dataset = paddle.audio.datasets.ESC50(mode=mode,
>>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode,
feat_type='raw')
... feat_type='raw')
for idx in range(5):
>>> for idx in range(5):
audio, label = esc50_dataset[idx]
... audio, label = esc50_dataset[idx]
# do something with audio, label
... # do something with audio, label
print(audio.shape, label)
... print(audio.shape, label)
# [audio_data_length] , label_id
... # [audio_data_length] , label_id
[220500] 0
esc50_dataset = paddle.audio.datasets.ESC50(mode=mode,
[220500] 14
feat_type='mfcc',
[220500] 36
n_mfcc=40)
[220500] 36
for idx in range(5):
[220500] 19
audio, label = esc50_dataset[idx]
# do something with mfcc feature, label
>>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode,
print(audio.shape, label)
... feat_type='mfcc',
# [feature_dim, length] , label_id
... n_mfcc=40)
>>> for idx in range(5):
... audio, label = esc50_dataset[idx]
... # do something with mfcc feature, label
... print(audio.shape, label)
... # [feature_dim, length] , label_id
[40, 1723] 0
[40, 1723] 14
[40, 1723] 36
[40, 1723] 36
[40, 1723] 19
"""
"""
archive
=
{
archive
=
{
...
...
python/paddle/audio/datasets/tess.py
浏览文件 @
e1eb52e1
...
@@ -49,25 +49,25 @@ class TESS(AudioClassificationDataset):
...
@@ -49,25 +49,25 @@ class TESS(AudioClassificationDataset):
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
mode = 'dev'
>>>
mode = 'dev'
tess_dataset = paddle.audio.datasets.TESS(mode=mode,
>>>
tess_dataset = paddle.audio.datasets.TESS(mode=mode,
feat_type='raw')
...
feat_type='raw')
for idx in range(5):
>>>
for idx in range(5):
audio, label = tess_dataset[idx]
...
audio, label = tess_dataset[idx]
# do something with audio, label
...
# do something with audio, label
print(audio.shape, label)
...
print(audio.shape, label)
# [audio_data_length] , label_id
...
# [audio_data_length] , label_id
tess_dataset = paddle.audio.datasets.TESS(mode=mode,
>>>
tess_dataset = paddle.audio.datasets.TESS(mode=mode,
feat_type='mfcc',
...
feat_type='mfcc',
n_mfcc=40)
...
n_mfcc=40)
for idx in range(5):
>>>
for idx in range(5):
audio, label = tess_dataset[idx]
...
audio, label = tess_dataset[idx]
# do something with mfcc feature, label
...
# do something with mfcc feature, label
print(audio.shape, label)
...
print(audio.shape, label)
# [feature_dim, num_frames] , label_id
...
# [feature_dim, num_frames] , label_id
"""
"""
archive
=
{
archive
=
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录