diffsptk 1.0.1__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {diffsptk-1.0.1 → diffsptk-1.2.1}/PKG-INFO +20 -8
- {diffsptk-1.0.1 → diffsptk-1.2.1}/README.md +15 -4
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/__init__.py +10 -1
- diffsptk-1.2.1/diffsptk/core/alaw.py +75 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/c2acr.py +1 -2
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/delay.py +1 -1
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/df2.py +9 -12
- diffsptk-1.2.1/diffsptk/core/dfs.py +142 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/excite.py +2 -1
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/fbank.py +12 -5
- diffsptk-1.2.1/diffsptk/core/ialaw.py +77 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/iulaw.py +3 -3
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/levdur.py +1 -1
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/linear_intpl.py +4 -4
- diffsptk-1.2.1/diffsptk/core/lpc2lsp.py +143 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/lpc2par.py +1 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/lpccheck.py +1 -1
- diffsptk-1.2.1/diffsptk/core/lsp2lpc.py +110 -0
- diffsptk-1.2.1/diffsptk/core/lsp2sp.py +152 -0
- diffsptk-1.2.1/diffsptk/core/lspcheck.py +108 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mfcc.py +7 -7
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mgc2mgc.py +3 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/par2lpc.py +2 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/pitch.py +5 -2
- diffsptk-1.2.1/diffsptk/core/plp.py +166 -0
- diffsptk-1.2.1/diffsptk/core/pol_root.py +66 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/root_pol.py +17 -66
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/stft.py +9 -7
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/ulaw.py +3 -3
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/zcross.py +3 -1
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/misc/__init__.py +1 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/misc/signals.py +4 -4
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/misc/utils.py +84 -13
- diffsptk-1.2.1/diffsptk/version.py +1 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/pyproject.toml +5 -3
- diffsptk-1.0.1/diffsptk/core/dfs.py +0 -107
- diffsptk-1.0.1/diffsptk/version.py +0 -1
- {diffsptk-1.0.1 → diffsptk-1.2.1}/.gitignore +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/LICENSE +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/__init__.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/acorr.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/ap.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/b2mc.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/c2mpir.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/c2ndps.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/cdist.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/cqt.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/dct.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/decimate.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/delta.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/dequantize.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/entropy.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/fftcep.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/frame.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/freqt.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/freqt2.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/gmm.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/gnorm.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/grpdelay.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/idct.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/ifreqt2.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/ignorm.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/imglsadf.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/imsvq.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/interpolate.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/ipqmf.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/istft.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/ivq.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/lar2par.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/lbg.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/lpc.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/magic_intpl.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mc2b.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mcep.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mcpf.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mgc2sp.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mgcep.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mglsadf.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mlpg.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mlsacheck.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/mpir2c.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/msvq.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/ndps2c.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/norm0.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/par2lar.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/pca.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/phase.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/poledf.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/pqmf.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/quantize.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/rlevdur.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/rmse.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/smcep.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/snr.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/spec.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/unframe.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/vq.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/window.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/yingram.py +0 -0
- {diffsptk-1.0.1 → diffsptk-1.2.1}/diffsptk/core/zerodf.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffsptk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: Speech signal processing modules for machine learning
|
|
5
5
|
Project-URL: Homepage, https://sp-tk.sourceforge.net/
|
|
6
6
|
Project-URL: Documentation, https://sp-nitech.github.io/diffsptk/latest/
|
|
@@ -17,11 +17,12 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
18
|
Requires-Python: >=3.8
|
|
19
19
|
Requires-Dist: numpy
|
|
20
|
-
Requires-Dist: soundfile
|
|
20
|
+
Requires-Dist: soundfile>=0.10.2
|
|
21
21
|
Requires-Dist: torch>=1.11.0
|
|
22
|
-
Requires-Dist:
|
|
22
|
+
Requires-Dist: torchaudio>=0.11.0
|
|
23
|
+
Requires-Dist: torchcrepe>=0.0.21
|
|
23
24
|
Requires-Dist: torchlpc>=0.2.0
|
|
24
|
-
Requires-Dist: vector-quantize-pytorch
|
|
25
|
+
Requires-Dist: vector-quantize-pytorch<=1.12.12,>=0.8.0
|
|
25
26
|
Provides-Extra: dev
|
|
26
27
|
Requires-Dist: black; extra == 'dev'
|
|
27
28
|
Requires-Dist: build; extra == 'dev'
|
|
@@ -40,10 +41,10 @@ diffsptk
|
|
|
40
41
|
*diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
|
|
41
42
|
|
|
42
43
|
[](https://sp-nitech.github.io/diffsptk/latest/)
|
|
43
|
-
[](https://sp-nitech.github.io/diffsptk/1.
|
|
44
|
+
[](https://sp-nitech.github.io/diffsptk/1.2.1/)
|
|
44
45
|
[](https://pepy.tech/project/diffsptk)
|
|
45
46
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
46
|
-
[](https://pypi.python.org/pypi/diffsptk)
|
|
47
48
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
48
49
|
[](https://app.codecov.io/gh/sp-nitech/diffsptk)
|
|
49
50
|
[](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
|
|
@@ -59,7 +60,8 @@ Requirements
|
|
|
59
60
|
|
|
60
61
|
Documentation
|
|
61
62
|
-------------
|
|
62
|
-
See [this page](https://sp-nitech.github.io/diffsptk/latest/) for a reference manual.
|
|
63
|
+
- See [this page](https://sp-nitech.github.io/diffsptk/latest/) for a reference manual.
|
|
64
|
+
- Our [paper](https://www.isca-speech.org/archive/ssw_2023/yoshimura23_ssw.html) is available on the ISCA Archive.
|
|
63
65
|
|
|
64
66
|
|
|
65
67
|
Installation
|
|
@@ -127,7 +129,7 @@ diffsptk.write("voiced.wav", x_voiced, sr)
|
|
|
127
129
|
diffsptk.write("unvoiced.wav", x_unvoiced, sr)
|
|
128
130
|
```
|
|
129
131
|
|
|
130
|
-
### Mel-spectrogram and
|
|
132
|
+
### Mel-spectrogram, MFCC, and PLP extraction
|
|
131
133
|
```python
|
|
132
134
|
import diffsptk
|
|
133
135
|
|
|
@@ -163,6 +165,16 @@ mfcc = diffsptk.MFCC(
|
|
|
163
165
|
)
|
|
164
166
|
Y = mfcc(X)
|
|
165
167
|
print(Y.shape)
|
|
168
|
+
|
|
169
|
+
# Extract PLP.
|
|
170
|
+
plp = diffsptk.PLP(
|
|
171
|
+
plp_order=M,
|
|
172
|
+
n_channel=n_channel,
|
|
173
|
+
fft_length=n_fft,
|
|
174
|
+
sample_rate=sr,
|
|
175
|
+
)
|
|
176
|
+
Y = plp(X)
|
|
177
|
+
print(Y.shape)
|
|
166
178
|
```
|
|
167
179
|
|
|
168
180
|
### Subband decomposition
|
|
@@ -3,10 +3,10 @@ diffsptk
|
|
|
3
3
|
*diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
|
|
4
4
|
|
|
5
5
|
[](https://sp-nitech.github.io/diffsptk/latest/)
|
|
6
|
-
[](https://sp-nitech.github.io/diffsptk/1.
|
|
6
|
+
[](https://sp-nitech.github.io/diffsptk/1.2.1/)
|
|
7
7
|
[](https://pepy.tech/project/diffsptk)
|
|
8
8
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
9
|
-
[](https://pypi.python.org/pypi/diffsptk)
|
|
10
10
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
11
11
|
[](https://app.codecov.io/gh/sp-nitech/diffsptk)
|
|
12
12
|
[](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
|
|
@@ -22,7 +22,8 @@ Requirements
|
|
|
22
22
|
|
|
23
23
|
Documentation
|
|
24
24
|
-------------
|
|
25
|
-
See [this page](https://sp-nitech.github.io/diffsptk/latest/) for a reference manual.
|
|
25
|
+
- See [this page](https://sp-nitech.github.io/diffsptk/latest/) for a reference manual.
|
|
26
|
+
- Our [paper](https://www.isca-speech.org/archive/ssw_2023/yoshimura23_ssw.html) is available on the ISCA Archive.
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
Installation
|
|
@@ -90,7 +91,7 @@ diffsptk.write("voiced.wav", x_voiced, sr)
|
|
|
90
91
|
diffsptk.write("unvoiced.wav", x_unvoiced, sr)
|
|
91
92
|
```
|
|
92
93
|
|
|
93
|
-
### Mel-spectrogram and
|
|
94
|
+
### Mel-spectrogram, MFCC, and PLP extraction
|
|
94
95
|
```python
|
|
95
96
|
import diffsptk
|
|
96
97
|
|
|
@@ -126,6 +127,16 @@ mfcc = diffsptk.MFCC(
|
|
|
126
127
|
)
|
|
127
128
|
Y = mfcc(X)
|
|
128
129
|
print(Y.shape)
|
|
130
|
+
|
|
131
|
+
# Extract PLP.
|
|
132
|
+
plp = diffsptk.PLP(
|
|
133
|
+
plp_order=M,
|
|
134
|
+
n_channel=n_channel,
|
|
135
|
+
fft_length=n_fft,
|
|
136
|
+
sample_rate=sr,
|
|
137
|
+
)
|
|
138
|
+
Y = plp(X)
|
|
139
|
+
print(Y.shape)
|
|
129
140
|
```
|
|
130
141
|
|
|
131
142
|
### Subband decomposition
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from .acorr import AutocorrelationAnalysis
|
|
2
|
+
from .alaw import ALawCompression
|
|
2
3
|
from .ap import Aperiodicity
|
|
3
4
|
from .b2mc import MLSADigitalFilterCoefficientsToMelCepstrum
|
|
4
5
|
from .c2acr import CepstrumToAutocorrelation
|
|
@@ -27,6 +28,7 @@ from .gmm import GaussianMixtureModeling
|
|
|
27
28
|
from .gmm import GaussianMixtureModeling as GMM
|
|
28
29
|
from .gnorm import GeneralizedCepstrumGainNormalization
|
|
29
30
|
from .grpdelay import GroupDelay
|
|
31
|
+
from .ialaw import ALawExpansion
|
|
30
32
|
from .idct import InverseDiscreteCosineTransform
|
|
31
33
|
from .idct import InverseDiscreteCosineTransform as IDCT
|
|
32
34
|
from .ifreqt2 import SecondOrderAllPassInverseFrequencyTransform
|
|
@@ -48,8 +50,12 @@ from .levdur import LevinsonDurbin
|
|
|
48
50
|
from .linear_intpl import LinearInterpolation
|
|
49
51
|
from .lpc import LinearPredictiveCodingAnalysis
|
|
50
52
|
from .lpc import LinearPredictiveCodingAnalysis as LPC
|
|
53
|
+
from .lpc2lsp import LinearPredictiveCoefficientsToLineSpectralPairs
|
|
51
54
|
from .lpc2par import LinearPredictiveCoefficientsToParcorCoefficients
|
|
52
55
|
from .lpccheck import LinearPredictiveCoefficientsStabilityCheck
|
|
56
|
+
from .lsp2lpc import LineSpectralPairsToLinearPredictiveCoefficients
|
|
57
|
+
from .lsp2sp import LineSpectralPairsToSpectrum
|
|
58
|
+
from .lspcheck import LineSpectralPairsStabilityCheck
|
|
53
59
|
from .magic_intpl import MagicNumberInterpolation
|
|
54
60
|
from .mc2b import MelCepstrumToMLSADigitalFilterCoefficients
|
|
55
61
|
from .mcpf import MelCepstrumPostfiltering
|
|
@@ -74,6 +80,9 @@ from .pca import PrincipalComponentAnalysis
|
|
|
74
80
|
from .pca import PrincipalComponentAnalysis as PCA
|
|
75
81
|
from .phase import Phase
|
|
76
82
|
from .pitch import Pitch
|
|
83
|
+
from .plp import PerceptualLinearPredictiveCoefficientsAnalysis
|
|
84
|
+
from .plp import PerceptualLinearPredictiveCoefficientsAnalysis as PLP
|
|
85
|
+
from .pol_root import RootsToPolynomial
|
|
77
86
|
from .poledf import AllPoleDigitalFilter
|
|
78
87
|
from .pqmf import PseudoQuadratureMirrorFilterBanks
|
|
79
88
|
from .pqmf import PseudoQuadratureMirrorFilterBanks as PQMF
|
|
@@ -81,7 +90,7 @@ from .quantize import UniformQuantization
|
|
|
81
90
|
from .rlevdur import ReverseLevinsonDurbin
|
|
82
91
|
from .rmse import RootMeanSquaredError
|
|
83
92
|
from .rmse import RootMeanSquaredError as RMSE
|
|
84
|
-
from .root_pol import
|
|
93
|
+
from .root_pol import PolynomialToRoots
|
|
85
94
|
from .smcep import SecondOrderAllPassMelCepstralAnalysis
|
|
86
95
|
from .snr import SignalToNoiseRatio
|
|
87
96
|
from .snr import SignalToNoiseRatio as SNR
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# ------------------------------------------------------------------------ #
|
|
2
|
+
# Copyright 2022 SPTK Working Group #
|
|
3
|
+
# #
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); #
|
|
5
|
+
# you may not use this file except in compliance with the License. #
|
|
6
|
+
# You may obtain a copy of the License at #
|
|
7
|
+
# #
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
|
9
|
+
# #
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
|
13
|
+
# See the License for the specific language governing permissions and #
|
|
14
|
+
# limitations under the License. #
|
|
15
|
+
# ------------------------------------------------------------------------ #
|
|
16
|
+
|
|
17
|
+
import math
|
|
18
|
+
|
|
19
|
+
import torch
|
|
20
|
+
import torch.nn as nn
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ALawCompression(nn.Module):
|
|
24
|
+
"""See `this page <https://sp-nitech.github.io/sptk/latest/main/alaw.html>`_
|
|
25
|
+
for details.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
abs_max : float > 0 [scalar]
|
|
30
|
+
Absolute maximum value of input.
|
|
31
|
+
|
|
32
|
+
a : float >= 1 [scalar]
|
|
33
|
+
Compression factor, :math:`A`.
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, abs_max=1, a=87.6):
|
|
38
|
+
super(ALawCompression, self).__init__()
|
|
39
|
+
|
|
40
|
+
self.abs_max = abs_max
|
|
41
|
+
self.a = a
|
|
42
|
+
|
|
43
|
+
assert 0 < self.abs_max
|
|
44
|
+
assert 1 <= self.a
|
|
45
|
+
|
|
46
|
+
self.const = self.abs_max / (1 + math.log(self.a))
|
|
47
|
+
|
|
48
|
+
def forward(self, x):
|
|
49
|
+
"""Compress waveform by A-law algorithm.
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
x : Tensor [shape=(...,)]
|
|
54
|
+
Waveform.
|
|
55
|
+
|
|
56
|
+
Returns
|
|
57
|
+
-------
|
|
58
|
+
y : Tensor [shape=(...,)]
|
|
59
|
+
Compressed waveform.
|
|
60
|
+
|
|
61
|
+
Examples
|
|
62
|
+
--------
|
|
63
|
+
>>> x = diffsptk.ramp(4)
|
|
64
|
+
>>> alaw = diffsptk.ALawCompression(4)
|
|
65
|
+
>>> y = alaw(x)
|
|
66
|
+
>>> y
|
|
67
|
+
tensor([0.0000, 2.9868, 3.4934, 3.7897, 4.0000])
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
x_abs = x.abs() / self.abs_max
|
|
71
|
+
x1 = self.a * x_abs
|
|
72
|
+
x2 = 1 + torch.log(x1)
|
|
73
|
+
condition = x_abs < (1 / self.a)
|
|
74
|
+
y = self.const * torch.sign(x) * torch.where(condition, x1, x2)
|
|
75
|
+
return y
|
|
@@ -68,6 +68,5 @@ class CepstrumToAutocorrelation(nn.Module):
|
|
|
68
68
|
"""
|
|
69
69
|
x = torch.fft.rfft(c, n=self.fft_length).real
|
|
70
70
|
x = torch.exp(2 * x)
|
|
71
|
-
r = torch.fft.hfft(x)[..., : self.acr_order + 1]
|
|
72
|
-
r = r / self.fft_length
|
|
71
|
+
r = torch.fft.hfft(x, norm="forward")[..., : self.acr_order + 1]
|
|
73
72
|
return r
|
|
@@ -68,7 +68,7 @@ class Delay(nn.Module):
|
|
|
68
68
|
|
|
69
69
|
"""
|
|
70
70
|
# Generate zeros if needed.
|
|
71
|
-
if self.start
|
|
71
|
+
if 0 < self.start or self.keeplen:
|
|
72
72
|
shape = list(x.shape)
|
|
73
73
|
shape[dim] = abs(self.start)
|
|
74
74
|
zeros = torch.zeros(*shape, dtype=x.dtype, device=x.device)
|
|
@@ -42,8 +42,8 @@ class SecondOrderDigitalFilter(nn.Module):
|
|
|
42
42
|
zero_bandwidth : float > 0 [scalar]
|
|
43
43
|
Zero bandwidth in Hz.
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
**kwargs : additional keyword arguments
|
|
46
|
+
See :func:`~diffsptk.InfiniteImpulseResponseDigitalFilter`.
|
|
47
47
|
|
|
48
48
|
"""
|
|
49
49
|
|
|
@@ -54,7 +54,7 @@ class SecondOrderDigitalFilter(nn.Module):
|
|
|
54
54
|
pole_bandwidth=None,
|
|
55
55
|
zero_frequency=None,
|
|
56
56
|
zero_bandwidth=None,
|
|
57
|
-
|
|
57
|
+
**kwargs,
|
|
58
58
|
):
|
|
59
59
|
super(SecondOrderDigitalFilter, self).__init__()
|
|
60
60
|
|
|
@@ -67,32 +67,29 @@ class SecondOrderDigitalFilter(nn.Module):
|
|
|
67
67
|
theta = 2 * math.pi * frequency / sample_rate
|
|
68
68
|
return [1, -2 * r * math.cos(theta), r * r]
|
|
69
69
|
|
|
70
|
-
param = {}
|
|
71
70
|
if pole_frequency is not None:
|
|
72
|
-
|
|
71
|
+
kwargs["a"] = get_filter_coefficients(
|
|
73
72
|
pole_frequency, pole_bandwidth, sample_rate
|
|
74
73
|
)
|
|
75
74
|
if zero_frequency is not None:
|
|
76
|
-
|
|
75
|
+
kwargs["b"] = get_filter_coefficients(
|
|
77
76
|
zero_frequency, zero_bandwidth, sample_rate
|
|
78
77
|
)
|
|
79
|
-
if ir_length is not None:
|
|
80
|
-
param["ir_length"] = ir_length
|
|
81
78
|
|
|
82
|
-
self.dfs = InfiniteImpulseResponseDigitalFilter(**
|
|
79
|
+
self.dfs = InfiniteImpulseResponseDigitalFilter(**kwargs)
|
|
83
80
|
|
|
84
81
|
def forward(self, x):
|
|
85
82
|
"""Apply a second order digital filter.
|
|
86
83
|
|
|
87
84
|
Parameters
|
|
88
85
|
----------
|
|
89
|
-
x : Tensor [shape=(
|
|
86
|
+
x : Tensor [shape=(..., T)]
|
|
90
87
|
Input waveform.
|
|
91
88
|
|
|
92
89
|
Returns
|
|
93
90
|
-------
|
|
94
|
-
y : Tensor [shape=(
|
|
95
|
-
|
|
91
|
+
y : Tensor [shape=(..., T)]
|
|
92
|
+
Filtered waveform.
|
|
96
93
|
|
|
97
94
|
Examples
|
|
98
95
|
--------
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# ------------------------------------------------------------------------ #
|
|
2
|
+
# Copyright 2022 SPTK Working Group #
|
|
3
|
+
# #
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); #
|
|
5
|
+
# you may not use this file except in compliance with the License. #
|
|
6
|
+
# You may obtain a copy of the License at #
|
|
7
|
+
# #
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
|
9
|
+
# #
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
|
13
|
+
# See the License for the specific language governing permissions and #
|
|
14
|
+
# limitations under the License. #
|
|
15
|
+
# ------------------------------------------------------------------------ #
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
import torch.nn as nn
|
|
19
|
+
import torch.nn.functional as F
|
|
20
|
+
|
|
21
|
+
from ..misc.utils import iir
|
|
22
|
+
from ..misc.utils import numpy_to_torch
|
|
23
|
+
from ..misc.utils import to_3d
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class InfiniteImpulseResponseDigitalFilter(nn.Module):
|
|
27
|
+
"""See `this page <https://sp-nitech.github.io/sptk/latest/main/dfs.html>`_
|
|
28
|
+
for details.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
b : List [shape=(M+1,)]
|
|
33
|
+
Numerator coefficients.
|
|
34
|
+
|
|
35
|
+
a : List [shape=(N+1,)]
|
|
36
|
+
Denominator coefficients.
|
|
37
|
+
|
|
38
|
+
ir_length : int >= 1 [scalar]
|
|
39
|
+
Length of impulse response (valid only if **mode** is 'fir').
|
|
40
|
+
|
|
41
|
+
mode : ['fir', 'iir']
|
|
42
|
+
If 'fir', filter is approximated by a finite impulse response.
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, b=None, a=None, ir_length=None, mode="fir"):
|
|
47
|
+
super(InfiniteImpulseResponseDigitalFilter, self).__init__()
|
|
48
|
+
|
|
49
|
+
self.mode = mode
|
|
50
|
+
|
|
51
|
+
if b is None:
|
|
52
|
+
b = [1]
|
|
53
|
+
if a is None:
|
|
54
|
+
a = [1]
|
|
55
|
+
b = np.asarray(b)
|
|
56
|
+
a = np.asarray(a)
|
|
57
|
+
|
|
58
|
+
if self.mode == "fir":
|
|
59
|
+
# Pre-compute impulse response.
|
|
60
|
+
if ir_length is None:
|
|
61
|
+
ir_length = len(b)
|
|
62
|
+
assert 1 <= ir_length
|
|
63
|
+
|
|
64
|
+
d = np.zeros(max(len(b), len(a)))
|
|
65
|
+
h = np.empty(ir_length)
|
|
66
|
+
a0 = a[0]
|
|
67
|
+
a1 = a[1:]
|
|
68
|
+
for t in range(ir_length):
|
|
69
|
+
x = a0 if t == 0 else 0
|
|
70
|
+
y = x - np.sum(d[: len(a1)] * a1)
|
|
71
|
+
|
|
72
|
+
d = np.roll(d, 1)
|
|
73
|
+
d[0] = y
|
|
74
|
+
|
|
75
|
+
y = np.sum(d[: len(b)] * b)
|
|
76
|
+
h[t] = y
|
|
77
|
+
h = h.reshape(1, 1, -1)
|
|
78
|
+
self.register_buffer("h", numpy_to_torch(h).flip(-1))
|
|
79
|
+
elif self.mode == "iir":
|
|
80
|
+
self.register_buffer("b", numpy_to_torch(b))
|
|
81
|
+
self.register_buffer("a", numpy_to_torch(a))
|
|
82
|
+
else:
|
|
83
|
+
raise ValueError(f"mode {mode} is not supported")
|
|
84
|
+
|
|
85
|
+
def forward(self, x, b=None, a=None):
|
|
86
|
+
"""Apply an IIR digital filter.
|
|
87
|
+
|
|
88
|
+
Parameters
|
|
89
|
+
----------
|
|
90
|
+
x : Tensor [shape=(..., T)]
|
|
91
|
+
Input waveform.
|
|
92
|
+
|
|
93
|
+
b : Tensor [shape=(M+1,)]
|
|
94
|
+
Numerator coefficients.
|
|
95
|
+
|
|
96
|
+
a : Tensor [shape=(N+1,)]
|
|
97
|
+
Denominator coefficients.
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
y : Tensor [shape=(..., T)]
|
|
102
|
+
Filtered waveform.
|
|
103
|
+
|
|
104
|
+
Examples
|
|
105
|
+
--------
|
|
106
|
+
>>> x = diffsptk.ramp(4)
|
|
107
|
+
>>> dfs = diffsptk.IIR(b=[1, -0.97])
|
|
108
|
+
>>> y = dfs(x)
|
|
109
|
+
>>> y
|
|
110
|
+
tensor([0.0000, 1.0000, 1.0300, 1.0600, 1.0900])
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
if self.mode == "fir":
|
|
114
|
+
y = self._forward_fir(x, b, a)
|
|
115
|
+
elif self.mode == "iir":
|
|
116
|
+
y = self._forward_iir(x, b, a)
|
|
117
|
+
else:
|
|
118
|
+
raise RuntimeError
|
|
119
|
+
return y
|
|
120
|
+
|
|
121
|
+
def _forward_fir(self, x, b=None, a=None):
|
|
122
|
+
if a is None and b is None:
|
|
123
|
+
h = self.h
|
|
124
|
+
elif a is None and b is not None:
|
|
125
|
+
h = b.view(1, 1, -1).flip(-1)
|
|
126
|
+
else:
|
|
127
|
+
raise ValueError("Denominator coefficients must be set via constructor")
|
|
128
|
+
|
|
129
|
+
y = to_3d(x)
|
|
130
|
+
y = F.pad(y, (h.size(-1) - 1, 0))
|
|
131
|
+
y = F.conv1d(y, h)
|
|
132
|
+
y = y.view_as(x)
|
|
133
|
+
return y
|
|
134
|
+
|
|
135
|
+
def _forward_iir(self, x, b=None, a=None):
|
|
136
|
+
if b is None:
|
|
137
|
+
b = self.b
|
|
138
|
+
if a is None:
|
|
139
|
+
a = self.a
|
|
140
|
+
|
|
141
|
+
y = iir(x, b, a)
|
|
142
|
+
return y
|
|
@@ -18,6 +18,7 @@ import torch
|
|
|
18
18
|
import torch.nn as nn
|
|
19
19
|
import torch.nn.functional as F
|
|
20
20
|
|
|
21
|
+
from ..misc.utils import TWO_PI
|
|
21
22
|
from ..misc.utils import UNVOICED_SYMBOL
|
|
22
23
|
from .linear_intpl import LinearInterpolation
|
|
23
24
|
|
|
@@ -107,7 +108,7 @@ class ExcitationGeneration(nn.Module):
|
|
|
107
108
|
e = torch.zeros_like(p)
|
|
108
109
|
e[pulse_pos] = torch.sqrt(p[pulse_pos])
|
|
109
110
|
elif self.voiced_region == "sinusoidal":
|
|
110
|
-
e = torch.sin(
|
|
111
|
+
e = torch.sin(TWO_PI * phase)
|
|
111
112
|
elif self.voiced_region == "sawtooth":
|
|
112
113
|
e = torch.fmod(phase, 2) - 1
|
|
113
114
|
else:
|
|
@@ -59,11 +59,13 @@ class MelFilterBankAnalysis(nn.Module):
|
|
|
59
59
|
f_min=0,
|
|
60
60
|
f_max=None,
|
|
61
61
|
floor=1e-5,
|
|
62
|
+
use_power=False,
|
|
62
63
|
out_format="y",
|
|
63
64
|
):
|
|
64
65
|
super(MelFilterBankAnalysis, self).__init__()
|
|
65
66
|
|
|
66
67
|
self.floor = floor
|
|
68
|
+
self.use_power = use_power
|
|
67
69
|
self.out_format = out_format
|
|
68
70
|
|
|
69
71
|
if f_max is None:
|
|
@@ -87,6 +89,9 @@ class MelFilterBankAnalysis(nn.Module):
|
|
|
87
89
|
def hz_to_mel(x):
|
|
88
90
|
return 1127 * np.log(x / 700 + 1)
|
|
89
91
|
|
|
92
|
+
def mel_to_hz(x):
|
|
93
|
+
return 700 * (np.exp(x / 1127) - 1)
|
|
94
|
+
|
|
90
95
|
lower_bin_index = max(1, int(f_min / sample_rate * fft_length + 1.5))
|
|
91
96
|
upper_bin_index = min(
|
|
92
97
|
fft_length // 2, int(f_max / sample_rate * fft_length + 0.5)
|
|
@@ -96,17 +101,18 @@ class MelFilterBankAnalysis(nn.Module):
|
|
|
96
101
|
mel_max = hz_to_mel(f_max)
|
|
97
102
|
|
|
98
103
|
seed = np.arange(1, n_channel + 2)
|
|
99
|
-
|
|
104
|
+
center_frequencies = (mel_max - mel_min) / (n_channel + 1) * seed + mel_min
|
|
105
|
+
self.center_frequencies = mel_to_hz(center_frequencies)
|
|
100
106
|
|
|
101
107
|
seed = np.arange(lower_bin_index, upper_bin_index)
|
|
102
108
|
mel = hz_to_mel(sample_rate * seed / fft_length)
|
|
103
|
-
lower_channel_map = [np.argmax(
|
|
109
|
+
lower_channel_map = [np.argmax(0 < (m <= center_frequencies)) for m in mel]
|
|
104
110
|
|
|
105
|
-
diff =
|
|
111
|
+
diff = center_frequencies - np.insert(center_frequencies[:-1], 0, mel_min)
|
|
106
112
|
weights = np.zeros((fft_length // 2 + 1, n_channel))
|
|
107
113
|
for i, k in enumerate(seed):
|
|
108
114
|
m = lower_channel_map[i]
|
|
109
|
-
w = (
|
|
115
|
+
w = (center_frequencies[max(0, m)] - mel[i]) / diff[max(0, m)]
|
|
110
116
|
if 0 < m:
|
|
111
117
|
weights[k, m - 1] += w
|
|
112
118
|
if m < n_channel:
|
|
@@ -141,7 +147,8 @@ class MelFilterBankAnalysis(nn.Module):
|
|
|
141
147
|
[3.3640, 3.4518, 2.7717, 0.5088]])
|
|
142
148
|
|
|
143
149
|
"""
|
|
144
|
-
y =
|
|
150
|
+
y = x if self.use_power else torch.sqrt(x)
|
|
151
|
+
y = torch.matmul(y, self.H)
|
|
145
152
|
y = torch.log(torch.clip(y, min=self.floor))
|
|
146
153
|
E = (2 * x[..., 1:-1]).sum(-1) + x[..., 0] + x[..., -1]
|
|
147
154
|
E = torch.log(E / (2 * (x.size(-1) - 1))).unsqueeze(-1)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# ------------------------------------------------------------------------ #
|
|
2
|
+
# Copyright 2022 SPTK Working Group #
|
|
3
|
+
# #
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); #
|
|
5
|
+
# you may not use this file except in compliance with the License. #
|
|
6
|
+
# You may obtain a copy of the License at #
|
|
7
|
+
# #
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
|
9
|
+
# #
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
|
13
|
+
# See the License for the specific language governing permissions and #
|
|
14
|
+
# limitations under the License. #
|
|
15
|
+
# ------------------------------------------------------------------------ #
|
|
16
|
+
|
|
17
|
+
import math
|
|
18
|
+
|
|
19
|
+
import torch
|
|
20
|
+
import torch.nn as nn
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ALawExpansion(nn.Module):
|
|
24
|
+
"""See `this page <https://sp-nitech.github.io/sptk/latest/main/ialaw.html>`_
|
|
25
|
+
for details.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
abs_max : float > 0 [scalar]
|
|
30
|
+
Absolute maximum value of input.
|
|
31
|
+
|
|
32
|
+
a : float >= 1 [scalar]
|
|
33
|
+
Compression factor, :math:`A`.
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, abs_max=1, a=87.6):
|
|
38
|
+
super(ALawExpansion, self).__init__()
|
|
39
|
+
|
|
40
|
+
self.abs_max = abs_max
|
|
41
|
+
self.a = a
|
|
42
|
+
|
|
43
|
+
assert 0 < self.abs_max
|
|
44
|
+
assert 1 <= self.a
|
|
45
|
+
|
|
46
|
+
self.const = self.abs_max / self.a
|
|
47
|
+
self.z = 1 + math.log(self.a)
|
|
48
|
+
|
|
49
|
+
def forward(self, y):
|
|
50
|
+
"""Expand waveform by A-law algorithm.
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
y : Tensor [shape=(...,)]
|
|
55
|
+
Compressed waveform.
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
x : Tensor [shape=(...,)]
|
|
60
|
+
Waveform.
|
|
61
|
+
|
|
62
|
+
Examples
|
|
63
|
+
--------
|
|
64
|
+
>>> x = diffsptk.ramp(4)
|
|
65
|
+
>>> alaw = diffsptk.ALawCompression(4)
|
|
66
|
+
>>> ialaw = diffsptk.ALawExpansion(4)
|
|
67
|
+
>>> x2 = ialaw(alaw(x))
|
|
68
|
+
>>> x2
|
|
69
|
+
tensor([0.0000, 1.0000, 2.0000, 3.0000, 4.0000])
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
y_abs = y.abs() / self.abs_max
|
|
73
|
+
y1 = self.z * y_abs
|
|
74
|
+
y2 = torch.exp(y1 - 1)
|
|
75
|
+
condition = y_abs < (1 / self.z)
|
|
76
|
+
x = self.const * torch.sign(y) * torch.where(condition, y1, y2)
|
|
77
|
+
return x
|
|
@@ -39,7 +39,7 @@ class MuLawExpansion(nn.Module):
|
|
|
39
39
|
self.mu = mu
|
|
40
40
|
|
|
41
41
|
assert 0 < self.abs_max
|
|
42
|
-
assert
|
|
42
|
+
assert 1 <= self.mu
|
|
43
43
|
|
|
44
44
|
self.const = self.abs_max / self.mu
|
|
45
45
|
|
|
@@ -66,6 +66,6 @@ class MuLawExpansion(nn.Module):
|
|
|
66
66
|
tensor([0.0000, 1.0000, 2.0000, 3.0000, 4.0000])
|
|
67
67
|
|
|
68
68
|
"""
|
|
69
|
-
|
|
70
|
-
x = self.const * torch.sign(y) * (torch.pow(1 + self.mu,
|
|
69
|
+
y_abs = y.abs() / self.abs_max
|
|
70
|
+
x = self.const * torch.sign(y) * (torch.pow(1 + self.mu, y_abs) - 1)
|
|
71
71
|
return x
|
|
@@ -23,7 +23,7 @@ from ..misc.utils import symmetric_toeplitz
|
|
|
23
23
|
|
|
24
24
|
class LevinsonDurbin(nn.Module):
|
|
25
25
|
"""See `this page <https://sp-nitech.github.io/sptk/latest/main/levdur.html>`_
|
|
26
|
-
for details.
|
|
26
|
+
for details. The implementation is based on a simple matrix inversion.
|
|
27
27
|
|
|
28
28
|
Parameters
|
|
29
29
|
----------
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
import torch.nn as nn
|
|
18
18
|
import torch.nn.functional as F
|
|
19
19
|
|
|
20
|
+
from ..misc.utils import replicate1
|
|
21
|
+
|
|
20
22
|
|
|
21
23
|
class LinearInterpolation(nn.Module):
|
|
22
24
|
"""Perform linear interpolation.
|
|
@@ -38,8 +40,6 @@ class LinearInterpolation(nn.Module):
|
|
|
38
40
|
|
|
39
41
|
assert 1 <= self.upsampling_factor
|
|
40
42
|
|
|
41
|
-
self.pad = nn.ReplicationPad1d((0, 1))
|
|
42
|
-
|
|
43
43
|
def forward(self, x):
|
|
44
44
|
"""Interpolate filter coefficients.
|
|
45
45
|
|
|
@@ -76,8 +76,8 @@ class LinearInterpolation(nn.Module):
|
|
|
76
76
|
assert x.dim() == 3, "Input must be 3D tensor"
|
|
77
77
|
B, T, D = x.shape
|
|
78
78
|
|
|
79
|
-
x = x.mT
|
|
80
|
-
x =
|
|
79
|
+
x = x.mT.contiguous() # (B, D, T)
|
|
80
|
+
x = replicate1(x, left=False)
|
|
81
81
|
x = F.interpolate(
|
|
82
82
|
x,
|
|
83
83
|
size=T * self.upsampling_factor + 1,
|