diffsptk 2.1.0__tar.gz → 2.2.0__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-2.1.0 → diffsptk-2.2.0}/.gitignore +3 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/PKG-INFO +78 -16
- {diffsptk-2.1.0 → diffsptk-2.2.0}/README.md +68 -7
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/functional.py +216 -8
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/misc/utils.py +19 -3
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/__init__.py +15 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/acorr.py +1 -1
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/acr2csm.py +1 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ap.py +5 -5
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/cdist.py +1 -3
- diffsptk-2.2.0/diffsptk/modules/chroma.py +132 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/dct.py +3 -3
- diffsptk-2.2.0/diffsptk/modules/dst.py +85 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/gmm.py +121 -55
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/gnorm.py +2 -2
- diffsptk-2.2.0/diffsptk/modules/idst.py +81 -0
- diffsptk-2.2.0/diffsptk/modules/imdct.py +160 -0
- diffsptk-2.2.0/diffsptk/modules/imdst.py +73 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/imglsadf.py +0 -8
- diffsptk-2.2.0/diffsptk/modules/ipnorm.py +71 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/istft.py +1 -1
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lbg.py +119 -32
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/levdur.py +18 -5
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/linear_intpl.py +1 -1
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lpc.py +9 -6
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lspcheck.py +2 -2
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/magic_intpl.py +1 -1
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mcpf.py +3 -3
- diffsptk-2.2.0/diffsptk/modules/mdct.py +163 -0
- diffsptk-2.2.0/diffsptk/modules/mdst.py +70 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mglsadf.py +5 -2
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/msvq.py +1 -5
- diffsptk-2.2.0/diffsptk/modules/pnorm.py +87 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/rmse.py +2 -2
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/snr.py +2 -2
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/stft.py +1 -2
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/vq.py +1 -5
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/window.py +11 -1
- diffsptk-2.2.0/diffsptk/version.py +1 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/pyproject.toml +9 -9
- diffsptk-2.1.0/diffsptk/version.py +0 -1
- {diffsptk-2.1.0 → diffsptk-2.2.0}/CITATION.cff +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/LICENSE +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/__init__.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/misc/__init__.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/misc/signals.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/alaw.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/b2mc.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/c2acr.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/c2mpir.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/c2ndps.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/cqt.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/csm2acr.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/decimate.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/delay.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/delta.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/dequantize.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/df2.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/dfs.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/drc.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/entropy.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/excite.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/fbank.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/fftcep.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/frame.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/freqt.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/freqt2.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/grpdelay.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/histogram.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ialaw.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/icqt.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/idct.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ifreqt2.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ignorm.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/imsvq.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/interpolate.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ipqmf.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/iulaw.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ivq.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lar2par.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lpc2lsp.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lpc2par.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lpccheck.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lsp2lpc.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/lsp2sp.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mc2b.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mcep.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mfcc.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mgc2mgc.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mgc2sp.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mgcep.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mlpg.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mlsacheck.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/mpir2c.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ndps2c.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/norm0.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/par2lar.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/par2lpc.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/pca.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/phase.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/pitch.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/plp.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/pol_root.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/poledf.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/pqmf.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/quantize.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/rlevdur.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/root_pol.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/smcep.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/spec.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/ulaw.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/unframe.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/yingram.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/zcross.py +0 -0
- {diffsptk-2.1.0 → diffsptk-2.2.0}/diffsptk/modules/zerodf.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffsptk
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
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/
|
|
@@ -13,24 +13,25 @@ Keywords: dsp,pytorch,signal processing,sptk
|
|
|
13
13
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
14
|
Classifier: Programming Language :: Python
|
|
15
15
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.9
|
|
22
21
|
Requires-Dist: librosa>=0.10.1
|
|
23
|
-
Requires-Dist: numpy<2.0.0
|
|
24
|
-
Requires-Dist: scipy<1.14.0
|
|
22
|
+
Requires-Dist: numpy<2.0.0,>=1.20.3
|
|
23
|
+
Requires-Dist: scipy<1.14.0,>=1.5.4
|
|
25
24
|
Requires-Dist: soundfile>=0.10.2
|
|
26
|
-
Requires-Dist: torch>=
|
|
27
|
-
Requires-Dist: torchaudio>=0.
|
|
28
|
-
Requires-Dist: torchcomp>=0.1.
|
|
25
|
+
Requires-Dist: torch>=2.0.0
|
|
26
|
+
Requires-Dist: torchaudio>=2.0.1
|
|
27
|
+
Requires-Dist: torchcomp>=0.1.0
|
|
29
28
|
Requires-Dist: torchcrepe>=0.0.21
|
|
30
29
|
Requires-Dist: torchlpc>=0.2.0
|
|
31
|
-
Requires-Dist:
|
|
30
|
+
Requires-Dist: tqdm>=4.15.0
|
|
31
|
+
Requires-Dist: vector-quantize-pytorch>=1.14.9
|
|
32
32
|
Provides-Extra: dev
|
|
33
33
|
Requires-Dist: build; extra == 'dev'
|
|
34
|
+
Requires-Dist: docstrfmt; extra == 'dev'
|
|
34
35
|
Requires-Dist: isort; extra == 'dev'
|
|
35
36
|
Requires-Dist: mdformat; extra == 'dev'
|
|
36
37
|
Requires-Dist: numpydoc; extra == 'dev'
|
|
@@ -47,10 +48,10 @@ Description-Content-Type: text/markdown
|
|
|
47
48
|
*diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
|
|
48
49
|
|
|
49
50
|
[](https://sp-nitech.github.io/diffsptk/latest/)
|
|
50
|
-
[](https://sp-nitech.github.io/diffsptk/2.
|
|
51
|
+
[](https://sp-nitech.github.io/diffsptk/2.2.0/)
|
|
51
52
|
[](https://pepy.tech/project/diffsptk)
|
|
52
53
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
53
|
-
[](https://pypi.python.org/pypi/diffsptk)
|
|
54
55
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
55
56
|
[](https://app.codecov.io/gh/sp-nitech/diffsptk)
|
|
56
57
|
[](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
|
|
@@ -59,8 +60,8 @@ Description-Content-Type: text/markdown
|
|
|
59
60
|
|
|
60
61
|
## Requirements
|
|
61
62
|
|
|
62
|
-
- Python 3.
|
|
63
|
-
- PyTorch
|
|
63
|
+
- Python 3.9+
|
|
64
|
+
- PyTorch 2.0.0+
|
|
64
65
|
|
|
65
66
|
## Documentation
|
|
66
67
|
|
|
@@ -106,7 +107,7 @@ mcep = diffsptk.MelCepstralAnalysis(cep_order=M, fft_length=n_fft, alpha=alpha,
|
|
|
106
107
|
mc = mcep(X)
|
|
107
108
|
|
|
108
109
|
# Reconstruct x.
|
|
109
|
-
mlsa = diffsptk.MLSA(filter_order=M, frame_period=fp, alpha=alpha, taylor_order=
|
|
110
|
+
mlsa = diffsptk.MLSA(filter_order=M, frame_period=fp, alpha=alpha, taylor_order=20)
|
|
110
111
|
x_hat = mlsa(mlsa(x, -mc), mc)
|
|
111
112
|
|
|
112
113
|
# Write reconstructed waveform.
|
|
@@ -134,6 +135,41 @@ diffsptk.write("voiced.wav", x_voiced, sr)
|
|
|
134
135
|
diffsptk.write("unvoiced.wav", x_unvoiced, sr)
|
|
135
136
|
```
|
|
136
137
|
|
|
138
|
+
### LPC analysis and synthesis
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
import diffsptk
|
|
142
|
+
|
|
143
|
+
fl = 400 # Frame length.
|
|
144
|
+
fp = 80 # Frame period.
|
|
145
|
+
M = 24 # LPC dimensions.
|
|
146
|
+
|
|
147
|
+
# Read waveform.
|
|
148
|
+
x, sr = diffsptk.read("assets/data.wav")
|
|
149
|
+
|
|
150
|
+
# Estimate LPC of x.
|
|
151
|
+
frame = diffsptk.Frame(frame_length=fl, frame_period=fp)
|
|
152
|
+
window = diffsptk.Window(in_length=fl)
|
|
153
|
+
lpc = diffsptk.LPC(frame_length=fl, lpc_order=M, eps=1e-6)
|
|
154
|
+
a = lpc(window(frame(x)))
|
|
155
|
+
|
|
156
|
+
# Convert to inverse filter coefficients.
|
|
157
|
+
norm0 = diffsptk.AllPoleToAllZeroDigitalFilterCoefficients(filter_order=M)
|
|
158
|
+
b = norm0(a)
|
|
159
|
+
|
|
160
|
+
# Reconstruct x.
|
|
161
|
+
zerodf = diffsptk.AllZeroDigitalFilter(filter_order=M, frame_period=fp)
|
|
162
|
+
poledf = diffsptk.AllPoleDigitalFilter(filter_order=M, frame_period=fp)
|
|
163
|
+
x_hat = poledf(zerodf(x, b), a)
|
|
164
|
+
|
|
165
|
+
# Write reconstructed waveform.
|
|
166
|
+
diffsptk.write("reconst.wav", x_hat, sr)
|
|
167
|
+
|
|
168
|
+
# Compute error.
|
|
169
|
+
error = (x_hat - x).abs().sum()
|
|
170
|
+
print(error)
|
|
171
|
+
```
|
|
172
|
+
|
|
137
173
|
### Mel-spectrogram, MFCC, and PLP extraction
|
|
138
174
|
|
|
139
175
|
```python
|
|
@@ -152,8 +188,8 @@ x, sr = diffsptk.read("assets/data.wav")
|
|
|
152
188
|
stft = diffsptk.STFT(frame_length=fl, frame_period=fp, fft_length=n_fft)
|
|
153
189
|
X = stft(x)
|
|
154
190
|
|
|
155
|
-
# Extract mel-spectrogram.
|
|
156
|
-
fbank = diffsptk.
|
|
191
|
+
# Extract log mel-spectrogram.
|
|
192
|
+
fbank = diffsptk.MelFilterBankAnalysis(
|
|
157
193
|
n_channel=n_channel,
|
|
158
194
|
fft_length=n_fft,
|
|
159
195
|
sample_rate=sr,
|
|
@@ -240,6 +276,32 @@ error = (x_hat - x).abs().sum()
|
|
|
240
276
|
print(error)
|
|
241
277
|
```
|
|
242
278
|
|
|
279
|
+
### Modified discrete cosine transform
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
import diffsptk
|
|
283
|
+
|
|
284
|
+
fl = 512 # Frame length.
|
|
285
|
+
|
|
286
|
+
# Read waveform.
|
|
287
|
+
x, sr = diffsptk.read("assets/data.wav")
|
|
288
|
+
|
|
289
|
+
# Transform x.
|
|
290
|
+
mdct = diffsptk.MDCT(fl)
|
|
291
|
+
c = mdct(x)
|
|
292
|
+
|
|
293
|
+
# Reconstruct x.
|
|
294
|
+
imdct = diffpstk.IMDCT(fl)
|
|
295
|
+
x_hat = imdct(c, out_length=x.size(0))
|
|
296
|
+
|
|
297
|
+
# Write reconstructed waveform.
|
|
298
|
+
diffsptk.write("reconst.wav", x_hat, sr)
|
|
299
|
+
|
|
300
|
+
# Compute error.
|
|
301
|
+
error = (x_hat - x).abs().sum()
|
|
302
|
+
print(error)
|
|
303
|
+
```
|
|
304
|
+
|
|
243
305
|
### Vector quantization
|
|
244
306
|
|
|
245
307
|
```python
|
|
@@ -3,10 +3,10 @@
|
|
|
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/2.
|
|
6
|
+
[](https://sp-nitech.github.io/diffsptk/2.2.0/)
|
|
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)
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
## Requirements
|
|
17
17
|
|
|
18
|
-
- Python 3.
|
|
19
|
-
- PyTorch
|
|
18
|
+
- Python 3.9+
|
|
19
|
+
- PyTorch 2.0.0+
|
|
20
20
|
|
|
21
21
|
## Documentation
|
|
22
22
|
|
|
@@ -62,7 +62,7 @@ mcep = diffsptk.MelCepstralAnalysis(cep_order=M, fft_length=n_fft, alpha=alpha,
|
|
|
62
62
|
mc = mcep(X)
|
|
63
63
|
|
|
64
64
|
# Reconstruct x.
|
|
65
|
-
mlsa = diffsptk.MLSA(filter_order=M, frame_period=fp, alpha=alpha, taylor_order=
|
|
65
|
+
mlsa = diffsptk.MLSA(filter_order=M, frame_period=fp, alpha=alpha, taylor_order=20)
|
|
66
66
|
x_hat = mlsa(mlsa(x, -mc), mc)
|
|
67
67
|
|
|
68
68
|
# Write reconstructed waveform.
|
|
@@ -90,6 +90,41 @@ diffsptk.write("voiced.wav", x_voiced, sr)
|
|
|
90
90
|
diffsptk.write("unvoiced.wav", x_unvoiced, sr)
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
### LPC analysis and synthesis
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import diffsptk
|
|
97
|
+
|
|
98
|
+
fl = 400 # Frame length.
|
|
99
|
+
fp = 80 # Frame period.
|
|
100
|
+
M = 24 # LPC dimensions.
|
|
101
|
+
|
|
102
|
+
# Read waveform.
|
|
103
|
+
x, sr = diffsptk.read("assets/data.wav")
|
|
104
|
+
|
|
105
|
+
# Estimate LPC of x.
|
|
106
|
+
frame = diffsptk.Frame(frame_length=fl, frame_period=fp)
|
|
107
|
+
window = diffsptk.Window(in_length=fl)
|
|
108
|
+
lpc = diffsptk.LPC(frame_length=fl, lpc_order=M, eps=1e-6)
|
|
109
|
+
a = lpc(window(frame(x)))
|
|
110
|
+
|
|
111
|
+
# Convert to inverse filter coefficients.
|
|
112
|
+
norm0 = diffsptk.AllPoleToAllZeroDigitalFilterCoefficients(filter_order=M)
|
|
113
|
+
b = norm0(a)
|
|
114
|
+
|
|
115
|
+
# Reconstruct x.
|
|
116
|
+
zerodf = diffsptk.AllZeroDigitalFilter(filter_order=M, frame_period=fp)
|
|
117
|
+
poledf = diffsptk.AllPoleDigitalFilter(filter_order=M, frame_period=fp)
|
|
118
|
+
x_hat = poledf(zerodf(x, b), a)
|
|
119
|
+
|
|
120
|
+
# Write reconstructed waveform.
|
|
121
|
+
diffsptk.write("reconst.wav", x_hat, sr)
|
|
122
|
+
|
|
123
|
+
# Compute error.
|
|
124
|
+
error = (x_hat - x).abs().sum()
|
|
125
|
+
print(error)
|
|
126
|
+
```
|
|
127
|
+
|
|
93
128
|
### Mel-spectrogram, MFCC, and PLP extraction
|
|
94
129
|
|
|
95
130
|
```python
|
|
@@ -108,8 +143,8 @@ x, sr = diffsptk.read("assets/data.wav")
|
|
|
108
143
|
stft = diffsptk.STFT(frame_length=fl, frame_period=fp, fft_length=n_fft)
|
|
109
144
|
X = stft(x)
|
|
110
145
|
|
|
111
|
-
# Extract mel-spectrogram.
|
|
112
|
-
fbank = diffsptk.
|
|
146
|
+
# Extract log mel-spectrogram.
|
|
147
|
+
fbank = diffsptk.MelFilterBankAnalysis(
|
|
113
148
|
n_channel=n_channel,
|
|
114
149
|
fft_length=n_fft,
|
|
115
150
|
sample_rate=sr,
|
|
@@ -196,6 +231,32 @@ error = (x_hat - x).abs().sum()
|
|
|
196
231
|
print(error)
|
|
197
232
|
```
|
|
198
233
|
|
|
234
|
+
### Modified discrete cosine transform
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
import diffsptk
|
|
238
|
+
|
|
239
|
+
fl = 512 # Frame length.
|
|
240
|
+
|
|
241
|
+
# Read waveform.
|
|
242
|
+
x, sr = diffsptk.read("assets/data.wav")
|
|
243
|
+
|
|
244
|
+
# Transform x.
|
|
245
|
+
mdct = diffsptk.MDCT(fl)
|
|
246
|
+
c = mdct(x)
|
|
247
|
+
|
|
248
|
+
# Reconstruct x.
|
|
249
|
+
imdct = diffpstk.IMDCT(fl)
|
|
250
|
+
x_hat = imdct(c, out_length=x.size(0))
|
|
251
|
+
|
|
252
|
+
# Write reconstructed waveform.
|
|
253
|
+
diffsptk.write("reconst.wav", x_hat, sr)
|
|
254
|
+
|
|
255
|
+
# Compute error.
|
|
256
|
+
error = (x_hat - x).abs().sum()
|
|
257
|
+
print(error)
|
|
258
|
+
```
|
|
259
|
+
|
|
199
260
|
### Vector quantization
|
|
200
261
|
|
|
201
262
|
```python
|
|
@@ -204,6 +204,38 @@ def cdist(c1, c2, full=False, reduction="mean", eps=1e-8):
|
|
|
204
204
|
return nn.CepstralDistance._func(c1, c2, full=full, reduction=reduction, eps=eps)
|
|
205
205
|
|
|
206
206
|
|
|
207
|
+
def chroma(x, n_channel, sample_rate, norm=float("inf")):
|
|
208
|
+
"""Apply chroma-filter banks to STFT.
|
|
209
|
+
|
|
210
|
+
Parameters
|
|
211
|
+
----------
|
|
212
|
+
x : Tensor [shape=(..., L/2+1)]
|
|
213
|
+
Power spectrum.
|
|
214
|
+
|
|
215
|
+
n_channel : int >= 1
|
|
216
|
+
Number of chroma-filter banks, :math:`C`.
|
|
217
|
+
|
|
218
|
+
sample_rate : int >= 1
|
|
219
|
+
Sample rate in Hz.
|
|
220
|
+
|
|
221
|
+
norm : float
|
|
222
|
+
Normalization factor.
|
|
223
|
+
|
|
224
|
+
Returns
|
|
225
|
+
-------
|
|
226
|
+
out : Tensor [shape=(..., C)]
|
|
227
|
+
Chroma-filter bank output.
|
|
228
|
+
|
|
229
|
+
"""
|
|
230
|
+
return nn.ChromaFilterBankAnalysis._func(
|
|
231
|
+
x,
|
|
232
|
+
n_channel=n_channel,
|
|
233
|
+
sample_rate=sample_rate,
|
|
234
|
+
norm=norm,
|
|
235
|
+
use_power=True,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
|
|
207
239
|
def csm2acr(c):
|
|
208
240
|
"""Convert CSM coefficients to autocorrelation.
|
|
209
241
|
|
|
@@ -420,6 +452,23 @@ def drc(
|
|
|
420
452
|
)
|
|
421
453
|
|
|
422
454
|
|
|
455
|
+
def dst(x):
|
|
456
|
+
"""Compute DST.
|
|
457
|
+
|
|
458
|
+
Parameters
|
|
459
|
+
----------
|
|
460
|
+
x : Tensor [shape=(..., L)]
|
|
461
|
+
Input signal.
|
|
462
|
+
|
|
463
|
+
Returns
|
|
464
|
+
-------
|
|
465
|
+
out : Tensor [shape=(..., L)]
|
|
466
|
+
DST output.
|
|
467
|
+
|
|
468
|
+
"""
|
|
469
|
+
return nn.DiscreteSineTransform._func(x)
|
|
470
|
+
|
|
471
|
+
|
|
423
472
|
def entropy(p, out_format="nat"):
|
|
424
473
|
"""Calculate entropy.
|
|
425
474
|
|
|
@@ -769,6 +818,23 @@ def idct(y):
|
|
|
769
818
|
return nn.InverseDiscreteCosineTransform._func(y)
|
|
770
819
|
|
|
771
820
|
|
|
821
|
+
def idst(y):
|
|
822
|
+
"""Compute inverse DST.
|
|
823
|
+
|
|
824
|
+
Parameters
|
|
825
|
+
----------
|
|
826
|
+
y : Tensor [shape=(..., L)]
|
|
827
|
+
Input.
|
|
828
|
+
|
|
829
|
+
Returns
|
|
830
|
+
-------
|
|
831
|
+
out : Tensor [shape=(..., L)]
|
|
832
|
+
Inverse DST output.
|
|
833
|
+
|
|
834
|
+
"""
|
|
835
|
+
return nn.InverseDiscreteSineTransform._func(y)
|
|
836
|
+
|
|
837
|
+
|
|
772
838
|
def ifreqt2(c, out_order, alpha=0, theta=0, n_fft=512):
|
|
773
839
|
"""Perform second-order all-pass inverse frequency transform.
|
|
774
840
|
|
|
@@ -823,6 +889,52 @@ def ignorm(y, gamma=0, c=None):
|
|
|
823
889
|
return nn.GeneralizedCepstrumInverseGainNormalization._func(y, gamma=gamma, c=c)
|
|
824
890
|
|
|
825
891
|
|
|
892
|
+
def imdct(y, out_length=None, frame_length=400, window="sine"):
|
|
893
|
+
"""Compute inverse modified discrete cosine transform.
|
|
894
|
+
|
|
895
|
+
Parameters
|
|
896
|
+
----------
|
|
897
|
+
y : Tensor [shape=(..., 2T/L, L/2)]
|
|
898
|
+
Spectrum.
|
|
899
|
+
|
|
900
|
+
out_length : int or None
|
|
901
|
+
Length of output waveform.
|
|
902
|
+
|
|
903
|
+
frame_length : int >= 2
|
|
904
|
+
Frame length, :math:`L`.
|
|
905
|
+
|
|
906
|
+
window : ['sine', 'vorbis', 'kbd', 'rectangular']
|
|
907
|
+
Window type.
|
|
908
|
+
|
|
909
|
+
"""
|
|
910
|
+
return nn.InverseModifiedDiscreteCosineTransform._func(
|
|
911
|
+
y, out_length=out_length, frame_length=frame_length, window=window
|
|
912
|
+
)
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
def imdst(y, out_length=None, frame_length=400, window="sine"):
|
|
916
|
+
"""Compute inverse modified discrete sine transform.
|
|
917
|
+
|
|
918
|
+
Parameters
|
|
919
|
+
----------
|
|
920
|
+
y : Tensor [shape=(..., 2T/L, L/2)]
|
|
921
|
+
Spectrum.
|
|
922
|
+
|
|
923
|
+
out_length : int or None
|
|
924
|
+
Length of output waveform.
|
|
925
|
+
|
|
926
|
+
frame_length : int >= 2
|
|
927
|
+
Frame length, :math:`L`.
|
|
928
|
+
|
|
929
|
+
window : ['sine', 'vorbis', 'kbd', 'rectangular']
|
|
930
|
+
Window type.
|
|
931
|
+
|
|
932
|
+
"""
|
|
933
|
+
return nn.InverseModifiedDiscreteSineTransform._func(
|
|
934
|
+
y, out_length=out_length, frame_length=frame_length, window=window
|
|
935
|
+
)
|
|
936
|
+
|
|
937
|
+
|
|
826
938
|
def interpolate(x, period=1, start=0, dim=-1):
|
|
827
939
|
"""Interpolate signal.
|
|
828
940
|
|
|
@@ -849,6 +961,23 @@ def interpolate(x, period=1, start=0, dim=-1):
|
|
|
849
961
|
return nn.Interpolation._func(x, period=period, start=start, dim=dim)
|
|
850
962
|
|
|
851
963
|
|
|
964
|
+
def ipnorm(y):
|
|
965
|
+
"""Perform cepstrum inverse power normalization.
|
|
966
|
+
|
|
967
|
+
Parameters
|
|
968
|
+
----------
|
|
969
|
+
y : Tensor [shape=(..., M+2)]
|
|
970
|
+
Power-normalized cepstrum.
|
|
971
|
+
|
|
972
|
+
Returns
|
|
973
|
+
-------
|
|
974
|
+
out : Tensor [shape=(..., M+1)]
|
|
975
|
+
Output cepstrum.
|
|
976
|
+
|
|
977
|
+
"""
|
|
978
|
+
return nn.MelCepstrumInversePowerNormalization._func(y)
|
|
979
|
+
|
|
980
|
+
|
|
852
981
|
def istft(
|
|
853
982
|
y,
|
|
854
983
|
*,
|
|
@@ -948,7 +1077,7 @@ def lar2par(g):
|
|
|
948
1077
|
return nn.LogAreaRatioToParcorCoefficients._func(g)
|
|
949
1078
|
|
|
950
1079
|
|
|
951
|
-
def levdur(r):
|
|
1080
|
+
def levdur(r, eps=0):
|
|
952
1081
|
"""Solve a Yule-Walker linear system.
|
|
953
1082
|
|
|
954
1083
|
Parameters
|
|
@@ -956,13 +1085,16 @@ def levdur(r):
|
|
|
956
1085
|
r : Tensor [shape=(..., M+1)]
|
|
957
1086
|
Autocorrelation.
|
|
958
1087
|
|
|
1088
|
+
eps : float >= 0
|
|
1089
|
+
A small value to improve numerical stability.
|
|
1090
|
+
|
|
959
1091
|
Returns
|
|
960
1092
|
-------
|
|
961
1093
|
out : Tensor [shape=(..., M+1)]
|
|
962
1094
|
Gain and LPC coefficients.
|
|
963
1095
|
|
|
964
1096
|
"""
|
|
965
|
-
return nn.LevinsonDurbin._func(r)
|
|
1097
|
+
return nn.LevinsonDurbin._func(r, eps=eps)
|
|
966
1098
|
|
|
967
1099
|
|
|
968
1100
|
def linear_intpl(x, upsampling_factor=80):
|
|
@@ -985,7 +1117,7 @@ def linear_intpl(x, upsampling_factor=80):
|
|
|
985
1117
|
return nn.LinearInterpolation._func(x, upsampling_factor=upsampling_factor)
|
|
986
1118
|
|
|
987
1119
|
|
|
988
|
-
def lpc(x, lpc_order):
|
|
1120
|
+
def lpc(x, lpc_order, eps=1e-6):
|
|
989
1121
|
"""Compute LPC coefficients.
|
|
990
1122
|
|
|
991
1123
|
Parameters
|
|
@@ -996,13 +1128,16 @@ def lpc(x, lpc_order):
|
|
|
996
1128
|
lpc_order : int >= 0
|
|
997
1129
|
Order of LPC, :math:`M`.
|
|
998
1130
|
|
|
1131
|
+
eps : float >= 0
|
|
1132
|
+
A small value to improve numerical stability.
|
|
1133
|
+
|
|
999
1134
|
Returns
|
|
1000
1135
|
-------
|
|
1001
1136
|
out : Tensor [shape=(..., M+1)]
|
|
1002
1137
|
Gain and LPC coefficients.
|
|
1003
1138
|
|
|
1004
1139
|
"""
|
|
1005
|
-
return nn.LinearPredictiveCodingAnalysis._func(x, lpc_order=lpc_order)
|
|
1140
|
+
return nn.LinearPredictiveCodingAnalysis._func(x, lpc_order=lpc_order, eps=eps)
|
|
1006
1141
|
|
|
1007
1142
|
|
|
1008
1143
|
def lpc2lsp(a, log_gain=False, sample_rate=None, out_format="radian"):
|
|
@@ -1212,6 +1347,56 @@ def mc2b(mc, alpha=0):
|
|
|
1212
1347
|
return nn.MelCepstrumToMLSADigitalFilterCoefficients._func(mc, alpha=alpha)
|
|
1213
1348
|
|
|
1214
1349
|
|
|
1350
|
+
def mdct(x, frame_length=400, window="sine"):
|
|
1351
|
+
"""Compute modified discrete cosine transform.
|
|
1352
|
+
|
|
1353
|
+
Parameters
|
|
1354
|
+
----------
|
|
1355
|
+
x : Tensor [shape=(..., T)]
|
|
1356
|
+
Waveform.
|
|
1357
|
+
|
|
1358
|
+
frame_length : int >= 2
|
|
1359
|
+
Frame length, :math:`L`.
|
|
1360
|
+
|
|
1361
|
+
window : ['sine', 'vorbis', 'kbd', 'rectangular']
|
|
1362
|
+
Window type.
|
|
1363
|
+
|
|
1364
|
+
Returns
|
|
1365
|
+
-------
|
|
1366
|
+
out : Tensor [shape=(..., 2T/L, L/2)]
|
|
1367
|
+
Spectrum.
|
|
1368
|
+
|
|
1369
|
+
"""
|
|
1370
|
+
return nn.ModifiedDiscreteCosineTransform._func(
|
|
1371
|
+
x, frame_length=frame_length, window=window
|
|
1372
|
+
)
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
def mdst(x, frame_length=400, window="sine"):
|
|
1376
|
+
"""Compute modified discrete sine transform.
|
|
1377
|
+
|
|
1378
|
+
Parameters
|
|
1379
|
+
----------
|
|
1380
|
+
x : Tensor [shape=(..., T)]
|
|
1381
|
+
Waveform.
|
|
1382
|
+
|
|
1383
|
+
frame_length : int >= 2
|
|
1384
|
+
Frame length, :math:`L`.
|
|
1385
|
+
|
|
1386
|
+
window : ['sine', 'vorbis', 'kbd', 'rectangular']
|
|
1387
|
+
Window type.
|
|
1388
|
+
|
|
1389
|
+
Returns
|
|
1390
|
+
-------
|
|
1391
|
+
out : Tensor [shape=(..., 2T/L, L/2)]
|
|
1392
|
+
Spectrum.
|
|
1393
|
+
|
|
1394
|
+
"""
|
|
1395
|
+
return nn.ModifiedDiscreteSineTransform._func(
|
|
1396
|
+
x, frame_length=frame_length, window=window
|
|
1397
|
+
)
|
|
1398
|
+
|
|
1399
|
+
|
|
1215
1400
|
def mgc2mgc(
|
|
1216
1401
|
mc,
|
|
1217
1402
|
out_order,
|
|
@@ -1552,6 +1737,29 @@ def phase(b=None, a=None, *, fft_length=512, unwrap=False):
|
|
|
1552
1737
|
return nn.Phase._func(b, a, fft_length=fft_length, unwrap=unwrap)
|
|
1553
1738
|
|
|
1554
1739
|
|
|
1740
|
+
def pnorm(x, alpha=0, ir_length=128):
|
|
1741
|
+
"""Perform cepstrum power normalization.
|
|
1742
|
+
|
|
1743
|
+
Parameters
|
|
1744
|
+
----------
|
|
1745
|
+
x : Tensor [shape=(..., M+1)]
|
|
1746
|
+
Input cepstrum.
|
|
1747
|
+
|
|
1748
|
+
alpha : float in (-1, 1)
|
|
1749
|
+
Frequency warping factor, :math:`\\alpha`.
|
|
1750
|
+
|
|
1751
|
+
ir_length : int >= 1
|
|
1752
|
+
Length of impulse response.
|
|
1753
|
+
|
|
1754
|
+
Returns
|
|
1755
|
+
-------
|
|
1756
|
+
out : Tensor [shape=(..., M+2)]
|
|
1757
|
+
Power-normalized cepstrum.
|
|
1758
|
+
|
|
1759
|
+
"""
|
|
1760
|
+
return nn.MelCepstrumPowerNormalization._func(x, alpha=alpha, ir_length=ir_length)
|
|
1761
|
+
|
|
1762
|
+
|
|
1555
1763
|
def pol_root(x, real=False):
|
|
1556
1764
|
"""Compute polynomial coefficients from roots.
|
|
1557
1765
|
|
|
@@ -1650,10 +1858,10 @@ def rmse(x, y, reduction="mean", eps=1e-8):
|
|
|
1650
1858
|
|
|
1651
1859
|
Parameters
|
|
1652
1860
|
----------
|
|
1653
|
-
x : Tensor [shape=(...,)]
|
|
1861
|
+
x : Tensor [shape=(..., T)]
|
|
1654
1862
|
Input.
|
|
1655
1863
|
|
|
1656
|
-
y : Tensor [shape=(...,)]
|
|
1864
|
+
y : Tensor [shape=(..., T)]
|
|
1657
1865
|
Target.
|
|
1658
1866
|
|
|
1659
1867
|
reduction : ['none', 'mean', 'sum']
|
|
@@ -1696,10 +1904,10 @@ def snr(s, sn, frame_length=None, full=False, reduction="mean", eps=1e-8):
|
|
|
1696
1904
|
|
|
1697
1905
|
Parameters
|
|
1698
1906
|
----------
|
|
1699
|
-
s : Tensor [shape=(...,)]
|
|
1907
|
+
s : Tensor [shape=(..., T)]
|
|
1700
1908
|
Signal.
|
|
1701
1909
|
|
|
1702
|
-
sn : Tensor [shape=(...,)]
|
|
1910
|
+
sn : Tensor [shape=(..., T)]
|
|
1703
1911
|
Signal plus noise.
|
|
1704
1912
|
|
|
1705
1913
|
frame_length : int >= 1 or None
|
|
@@ -76,10 +76,10 @@ def numpy_to_torch(x):
|
|
|
76
76
|
return torch.from_numpy(x.astype(default_dtype()))
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
def to(x, dtype=None):
|
|
79
|
+
def to(x, dtype=None, device=None):
|
|
80
80
|
if dtype is None:
|
|
81
81
|
dtype = torch.get_default_dtype()
|
|
82
|
-
return x.to(dtype=dtype)
|
|
82
|
+
return x.to(dtype=dtype, device=device)
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
def to_2d(x):
|
|
@@ -92,6 +92,22 @@ def to_3d(x):
|
|
|
92
92
|
return y
|
|
93
93
|
|
|
94
94
|
|
|
95
|
+
def to_dataloader(x, batch_size=None):
|
|
96
|
+
if torch.is_tensor(x):
|
|
97
|
+
dataset = torch.utils.data.TensorDataset(x)
|
|
98
|
+
data_loader = torch.utils.data.DataLoader(
|
|
99
|
+
dataset,
|
|
100
|
+
batch_size=len(x) if batch_size is None else batch_size,
|
|
101
|
+
shuffle=False,
|
|
102
|
+
drop_last=False,
|
|
103
|
+
)
|
|
104
|
+
return data_loader
|
|
105
|
+
elif isinstance(x, torch.utils.data.DataLoader):
|
|
106
|
+
return x
|
|
107
|
+
else:
|
|
108
|
+
raise ValueError(f"Unsupported input type: {type(x)}.")
|
|
109
|
+
|
|
110
|
+
|
|
95
111
|
def reflect(x):
|
|
96
112
|
d = x.size(-1)
|
|
97
113
|
y = x.view(-1, d)
|
|
@@ -108,7 +124,7 @@ def replicate1(x, left=True, right=True):
|
|
|
108
124
|
return y
|
|
109
125
|
|
|
110
126
|
|
|
111
|
-
def remove_gain(a,
|
|
127
|
+
def remove_gain(a, value=1, return_gain=False):
|
|
112
128
|
K, a1 = torch.split(a, [1, a.size(-1) - 1], dim=-1)
|
|
113
129
|
a = F.pad(a1, (1, 0), value=value)
|
|
114
130
|
if return_gain:
|