Skip to content

Commit 6d16e69

Browse files
authored
add audio doc (#5299)
* add audio doc * fix typo * fix code link && punctuation * fix typo * fix features overivew link * add example * fix mfcc doc * add get_window * update code example * rm example * format * rm code example in cn
1 parent ecfd3a0 commit 6d16e69

13 files changed

+396
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _cn_overview_callbacks:
2+
3+
paddle.audio
4+
---------------------
5+
6+
paddle.audio 目录是飞桨在语音领域的高层 API。具体如下:
7+
8+
- :ref:`音频特征相关 API <about_features>`
9+
- :ref:`音频处理基础函数相关 API <about_functional>`
10+
11+
.. _about_features:
12+
13+
音频特征相关 API
14+
::::::::::::::::::::
15+
16+
.. csv-table::
17+
:header: "API 名称", "API 功能"
18+
:widths: 10, 30
19+
20+
" :ref:`LogMelSpectrogram <cn_api_audio_features_LogMelSpectrogram>` ", "计算语音特征 LogMelSpectrogram"
21+
" :ref:`MelSpectrogram <cn_api_audio_features_MelSpectrogram>` ", "计算语音特征 MelSpectrogram"
22+
" :ref:`MFCC <cn_api_audio_features_MFCC>` ", "计算语音特征 MFCC"
23+
" :ref:`Spectrogram <cn_api_audio_features_Spectrogram>` ", "计算语音特征 Spectrogram"
24+
25+
.. _about_functional:
26+
27+
音频处理基础函数相关 API
28+
::::::::::::::::::::
29+
30+
.. csv-table::
31+
:header: "API 名称", "API 功能"
32+
:widths: 10, 30
33+
34+
" :ref:`compute_fbank_matrix <cn_api_audio_functional_compute_fbank_matrix>` ", "计算 fbank 矩阵"
35+
" :ref:`create_dct <cn_api_audio_functional_create_dct>` ", "计算离散余弦变化矩阵"
36+
" :ref:`fft_frequencies <cn_api_audio_functional_fft_frequencies>` ", "计算离散傅里叶采样频率"
37+
" :ref:`hz_to_mel<cn_api_audio_functional_hz_to_mel>` ", "转换 hz 频率为 mel 频率"
38+
" :ref:`mel_to_hz<cn_api_audio_functional_mel_to_hz>` ", "转换 mel 频率为 hz 频率"
39+
" :ref:`mel_frequencies<cn_api_audio_functional_mel_frequencies>` ", "计算 mel 频率"
40+
" :ref:`power_to_db<cn_api_audio_functional_power_to_db>` ", "转换能量谱为分贝"
41+
" :ref:`get_window<cn_api_audio_functional_get_window>` ", "得到各种窗函数"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _cn_api_audio_features_LogMelSpectrogram:
2+
3+
LogMelSpectrogram
4+
-------------------------------
5+
6+
.. py:class:: paddle.audio.features.LogMelSpectrogram(sr=22050, n_fft=2048, hop_length=512, win_length=None, window='hann', power=2.0, center=True, pad_mode='reflect', n_mels=64, f_min=50.0, f_max=None, htk=False, norm='slaney', ref_value=1.0, amin=1e-10, top_db=None, dtype='float32')
7+
8+
计算给定信号的 log-mel 谱。
9+
10+
参数
11+
::::::::::::
12+
13+
- **sr** (int) - 采样率,默认 22050。
14+
- **n_fft** (int) - 离散傅里叶变换中频率窗大小,默认 512。
15+
- **hop_length** (int,可选) - 帧移,默认 512。
16+
- **win_length** (int,可选) - 短时 FFT 的窗长,默认为 None。
17+
- **window** (str) - 窗函数名,默认'hann'。
18+
- **power** (float) - 幅度谱的指数。
19+
- **center** (bool) - 对输入信号填充,如果 True,那么 t 以 t*hop_length 为中心,如果为 False,则 t 以 t*hop_length 开始。
20+
- **pad_mode** (str) - 如果 center 是 True,选择填充的方式,默认值是'reflect'。
21+
- **n_mels** (int) - mel bins 的数目。
22+
- **f_min** (float,可选) - 最小频率(hz),默认 50.0。
23+
- **f_max** (float,可选) - 最大频率(hz),默认为 None。
24+
- **htk** (bool,可选) - 在计算 fbank 矩阵时是否用在 HTK 公式缩放.
25+
- **norm** (Union[str,float],可选) - 计算 fbank 矩阵时正则化的种类,默认是'slaney',你也可以 norm=0.5,使用 p-norm 正则化.
26+
- **ref_value** (float) - 参照值,如果小于 1.0,信号的 db 会被提升,相反 db 会下降,默认值为 1.0.
27+
- **amin** (float) - 输入的幅值的最小值.
28+
- **top_db** (float,可选) - log-mel 谱的最大值(db).
29+
- **dtype** (str) - 输入和窗的数据类型,默认是'float32'.
30+
31+
32+
返回
33+
:::::::::
34+
35+
计算``LogMelSpectrogram``的可调用对象.
36+
37+
代码示例
38+
:::::::::
39+
40+
COPY-FROM: paddle.audio.features.layers.LogMelSpectrogram
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _cn_api_audio_features_MFCC:
2+
3+
MFCC
4+
-------------------------------
5+
6+
.. py:class:: paddle.audio.features.MFCC(sr=22050, n_mfcc=40, n_fft=2048, hop_length=512, win_length=None, window='hann', power=2.0, center=True, pad_mode='reflect', n_mels=64, f_min=50.0, f_max=None, htk=False, norm='slaney', ref_value=1.0, amin=1e-10, top_db=None, dtype='float32')
7+
8+
计算给定信号的 MFCC。
9+
10+
参数
11+
::::::::::::
12+
13+
- **sr** (int,可选) - 采样率,默认 22050。
14+
- **n_mfcc** (int,可选) - mfcc 的维度,默认 40。
15+
- **n_fft** (int) - 离散傅里叶变换中频率窗大小,默认 512。
16+
- **hop_length** (int,可选) - 帧移,默认 512。
17+
- **win_length** (int,可选) - 短时 FFT 的窗长,默认为 None。
18+
- **window** (str) - 窗函数名,默认'hann'。
19+
- **power** (float) - 幅度谱的指数。
20+
- **center** (bool) - 对输入信号填充,如果 True,那么 t 以 t*hop_length 为中心,如果为 False,则 t 以 t*hop_length 开始。
21+
- **pad_mode** (str) - 如果 center 是 True,选择填充的方式,默认值是'reflect'.
22+
- **n_mels** (int) - mel bins 的数目。
23+
- **f_min** (float,可选) - 最小频率(hz),默认 50.0。
24+
- **f_max** (float,可选) - 最大频率(hz),默认为 None。
25+
- **htk** (bool,可选) - 在计算 fbank 矩阵时是否用在 HTK 公式缩放。
26+
- **norm** (Union[str, float], optional) - 计算 fbank 矩阵时正则化的种类,默认是'slaney',你也可以 norm=0.5,使用 p-norm 正则化。
27+
- **ref_value** (float) - 参照值, 如果小于 1.0,信号的 db 会被提升, 相反 db 会下降, 默认值为 1.0。
28+
- **amin** (float) - 输入的幅值的最小值。
29+
- **top_db** (float,可选) - log-mel 谱的最大值(db)。
30+
- **dtype** (str) - 输入和窗的数据类型,默认是'float32'。
31+
32+
返回
33+
:::::::::
34+
35+
计算``MFCC``的可调用对象。
36+
37+
代码示例
38+
:::::::::
39+
40+
COPY-FROM: paddle.audio.features.layers.MFCC
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _cn_api_audio_features_MelSpectrogram:
2+
3+
MelSpectrogram
4+
-------------------------------
5+
6+
.. py:class:: paddle.audio.features.MelSpectrogram(sr=22050, n_fft=2048, hop_length=512, win_length=None, window='hann', power=2.0, center=True, pad_mode='reflect', n_mels=64, f_min=50.0, f_max=None, htk=False, norm='slaney', dtype='float32')
7+
8+
求得给定信号的 Mel 谱。
9+
10+
参数
11+
::::::::::::
12+
13+
- **sr** (int,可选) - 采样率,默认 22050。
14+
- **n_fft** (int) - 离散傅里叶变换中频率窗大小,默认 512。
15+
- **hop_length** (int,可选) - 帧移,默认 512。
16+
- **win_length** (int,可选) - 短时 FFT 的窗长,默认为 None。
17+
- **window** (str) - 窗函数名,默认'hann'。
18+
- **power** (float) - 幅度谱的指数。
19+
- **center** (bool) - 对输入信号填充,如果 True,那么 t 以 t*hop_length 为中心,如果为 False,则 t 以 t*hop_length 开始。
20+
- **pad_mode** (str) - 如果 center 是 True,选择填充的方式.默认值是'reflect'。
21+
- **n_mels** (int) - mel bins 的数目。
22+
- **f_min** (float,可选) - 最小频率(hz),默认 50.0。
23+
- **f_max** (float,可选) - 最大频率(hz),默认为 None。
24+
- **htk** (bool,可选) - 在计算 fbank 矩阵时是否用在 HTK 公式缩放。
25+
- **norm** (Union[str,float],可选) -计算 fbank 矩阵时正则化的种类,默认是'slaney',你也可以 norm=0.5,使用 p-norm 正则化。
26+
- **dtype** (str) - 输入和窗的数据类型,默认是'float32'。
27+
28+
29+
返回
30+
:::::::::
31+
32+
计算``MelSpectrogram``的可调用对象。
33+
34+
代码示例
35+
:::::::::
36+
37+
COPY-FROM: paddle.audio.features.MelSpectrogram
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _cn_api_audio_features_Spectrogram:
2+
3+
Spectrogram
4+
-------------------------------
5+
6+
.. py:class:: paddle.audio.features.Spectrogram(n_fft=512, hop_length=512, win_length=None, window='hann', power=1.0, center=True, pad_mode='reflect', dtype='float32')
7+
8+
通过给定信号的短时傅里叶变换得到频谱。
9+
10+
参数
11+
::::::::::::
12+
13+
- **n_fft** (int) - 离散傅里叶变换中频率窗大小,默认 512。
14+
- **hop_length** (int,可选) - 帧移,默认 512。
15+
- **win_length** (int,可选) - 短时 FFT 的窗长,默认为 None。
16+
- **window** (str) - 窗函数名,默认'hann'。
17+
- **power** (float) - 幅度谱的指数。
18+
- **center** (bool) - 对输入信号填充,如果 True,那么 t 以 t*hop_length 为中心,如果为 False,则 t 以 t*hop_length 开始。
19+
- **pad_mode** (str) - 如果 center 是 True,选择填充的方式.默认值是'reflect'。
20+
- **dtype** (str) - 输入和窗的数据类型,默认是'float32'。
21+
22+
23+
返回
24+
:::::::::
25+
26+
计算``Spectrogram``的可调用对象.
27+
28+
代码示例
29+
:::::::::
30+
COPY-FROM: paddle.audio.features.Spectrogram
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _cn_api_audio_functional_compute_fbank_matrix:
2+
3+
compute_fbank_matrix
4+
-------------------------------
5+
6+
.. py:function:: paddle.audio.functional.compute_fbank_matrix(sr, n_fft, n_mels=64, f_min=0.0, f_max=None, htk=False, nrom='slaney', dtype='float32')
7+
8+
计算 mel 变换矩阵。
9+
10+
参数
11+
::::::::::::
12+
13+
- **sr** (int) - 采样率。
14+
- **n_fft** (int) - fft bins 的数目。
15+
- **n_mels** (float) - mels bins 的数目。
16+
- **f_min** (float) - 最小频率(hz)。
17+
- **f_max** (Optional[float]) -最大频率(hz)。
18+
- **htk** (bool) -是否使用 htk 缩放。
19+
- **norm** (Union[str,float]) -norm 的类型,默认是'slaney'。
20+
- **dtype** (str) - 返回矩阵的数据类型,默认'float32'。
21+
22+
返回
23+
:::::::::
24+
25+
``paddle.Tensor``,Tensor shape (n_mels, n_fft//2 + 1)。
26+
27+
代码示例
28+
:::::::::
29+
30+
COPY-FROM: paddle.audio.functional.compute_fbank_matrix
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _cn_api_audio_functional_create_dct:
2+
3+
create_dct
4+
-------------------------------
5+
6+
.. py:function:: paddle.audio.functional.create_dct(n_mfcc, n_mels, norm='ortho', dtype='float32')
7+
8+
计算离散余弦变换矩阵。
9+
10+
参数
11+
::::::::::::
12+
13+
- **n_mfcc** (float) - mel 倒谱系数数目。
14+
- **n_mels** (int) - mel 的 fliterbank 数。
15+
- **norm** (float) - 正则化类型, 默认值是'ortho'。
16+
- **dtype** (str) - 默认'float32'。
17+
18+
返回
19+
:::::::::
20+
21+
``paddle.Tensor``,Tensor shape (n_mels, n_mfcc)。
22+
23+
代码示例
24+
:::::::::
25+
26+
COPY-FROM: paddle.audio.functional.create_dct
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.. _cn_api_audio_functional_fft_frequencies:
2+
3+
fft_frequencies
4+
-------------------------------
5+
6+
.. py:function:: paddle.audio.functional.fft_frequencies(sr, n_fft, dtype='float32')
7+
8+
计算 fft 频率。
9+
10+
参数
11+
::::::::::::
12+
13+
- **sr** (int) - 采样率。
14+
- **n_fft** (int) - fft bins 的数目。
15+
- **dtype** (str) - 默认'float32'。
16+
17+
返回
18+
:::::::::
19+
20+
``paddle.Tensor``,Tensor shape (n_fft//2 + 1,)。
21+
22+
代码示例
23+
:::::::::
24+
25+
COPY-FROM: paddle.audio.functional.fft_frequencies
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _cn_api_audio_functional_get_window:
2+
3+
get_window
4+
-------------------------------
5+
6+
.. py:function:: paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64')
7+
8+
根据参数给出对应长度和类型的窗函数。
9+
10+
参数
11+
::::::::::::
12+
13+
- **window** (str 或者 Tuple[str, float]) - 窗函数类型,或者(窗参数类型, 窗函数参数), 支持的窗函数类型'hamming', 'hann', 'kaiser', 'gaussian', 'exponential', 'triang', 'bohman', 'blackman', 'cosine', 'tukey', 'taylor'。
14+
- **win_length** (int) - 采样点数。
15+
- **fftbins** (bool) - 如果是 True,给出一个周期性的窗, 如果是 False 给出一个对称性的窗,默认是 True。
16+
- **dtype** (str) - 默认'float64'。
17+
18+
返回
19+
:::::::::
20+
21+
``paddle.Tensor``,对应窗表征的 Tensor 。
22+
23+
代码示例
24+
:::::::::
25+
26+
COPY-FROM: paddle.audio.functional.get_window
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. _cn_api_audio_functional_hz_to_mel:
2+
3+
hz_to_mel
4+
-------------------------------
5+
6+
.. py:function:: paddle.audio.functional.hz_to_mel(feq, htk=False)
7+
8+
转换 Hz 为 Mels。
9+
10+
参数
11+
::::::::::::
12+
13+
- **freq** (Tensor, float) - 输入 tensor。
14+
- **htk** (bool) - 是否使用 htk 缩放, 默认 False。
15+
16+
返回
17+
:::::::::
18+
19+
``paddle.Tensor 或 float``, mels 值。
20+
21+
代码示例
22+
:::::::::
23+
24+
COPY-FROM: paddle.audio.functional.hz_to_mel

0 commit comments

Comments
 (0)