diffsptk 3.0.2__tar.gz → 3.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.
Files changed (144) hide show
  1. {diffsptk-3.0.2 → diffsptk-3.2.0}/PKG-INFO +13 -24
  2. {diffsptk-3.0.2 → diffsptk-3.2.0}/README.md +12 -23
  3. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/functional.py +180 -2
  4. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/__init__.py +4 -0
  5. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ap.py +3 -9
  6. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/dfs.py +1 -1
  7. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/drc.py +1 -1
  8. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/fbank.py +24 -5
  9. diffsptk-3.2.0/diffsptk/modules/fftr.py +144 -0
  10. diffsptk-3.2.0/diffsptk/modules/griffin.py +272 -0
  11. diffsptk-3.2.0/diffsptk/modules/ifftr.py +132 -0
  12. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/imdct.py +8 -5
  13. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/imdst.py +1 -1
  14. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/istft.py +40 -18
  15. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lbg.py +4 -3
  16. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lpc.py +1 -1
  17. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mcep.py +1 -1
  18. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mcpf.py +1 -1
  19. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mdct.py +7 -6
  20. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mdst.py +1 -1
  21. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mfcc.py +16 -1
  22. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mgc2mgc.py +1 -1
  23. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mgc2sp.py +1 -1
  24. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mglsadf.py +1 -1
  25. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/pitch_spec.py +6 -18
  26. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/plp.py +13 -1
  27. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/pnorm.py +1 -1
  28. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/smcep.py +1 -1
  29. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/spec.py +31 -9
  30. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/stft.py +41 -6
  31. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/unframe.py +29 -12
  32. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/window.py +18 -10
  33. diffsptk-3.2.0/diffsptk/modules/world_synth.py +297 -0
  34. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/librosa/constantq.py +28 -19
  35. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/librosa/filters.py +48 -41
  36. diffsptk-3.2.0/diffsptk/third_party/librosa/typing.py +29 -0
  37. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/librosa/util.py +23 -10
  38. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/world/common.py +70 -15
  39. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/utils/private.py +7 -7
  40. diffsptk-3.2.0/diffsptk/version.py +1 -0
  41. {diffsptk-3.0.2 → diffsptk-3.2.0}/pyproject.toml +4 -4
  42. diffsptk-3.0.2/diffsptk/version.py +0 -1
  43. {diffsptk-3.0.2 → diffsptk-3.2.0}/.gitignore +0 -0
  44. {diffsptk-3.0.2 → diffsptk-3.2.0}/CITATION.cff +0 -0
  45. {diffsptk-3.0.2 → diffsptk-3.2.0}/LICENSE +0 -0
  46. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/__init__.py +0 -0
  47. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/acorr.py +0 -0
  48. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/acr2csm.py +0 -0
  49. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/alaw.py +0 -0
  50. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/b2mc.py +0 -0
  51. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/base.py +0 -0
  52. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/c2acr.py +0 -0
  53. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/c2mpir.py +0 -0
  54. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/c2ndps.py +0 -0
  55. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/cdist.py +0 -0
  56. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/chroma.py +0 -0
  57. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/cqt.py +0 -0
  58. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/csm2acr.py +0 -0
  59. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/dct.py +0 -0
  60. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/decimate.py +0 -0
  61. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/delay.py +0 -0
  62. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/delta.py +0 -0
  63. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/dequantize.py +0 -0
  64. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/df2.py +0 -0
  65. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/dht.py +0 -0
  66. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/dst.py +0 -0
  67. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/entropy.py +0 -0
  68. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/excite.py +0 -0
  69. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/fftcep.py +0 -0
  70. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/flux.py +0 -0
  71. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/frame.py +0 -0
  72. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/freqt.py +0 -0
  73. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/freqt2.py +0 -0
  74. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/gammatone.py +0 -0
  75. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/gmm.py +0 -0
  76. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/gnorm.py +0 -0
  77. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/grpdelay.py +0 -0
  78. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/hilbert.py +0 -0
  79. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/hilbert2.py +0 -0
  80. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/histogram.py +0 -0
  81. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ialaw.py +0 -0
  82. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ica.py +0 -0
  83. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/icqt.py +0 -0
  84. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/idct.py +0 -0
  85. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/idht.py +0 -0
  86. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/idst.py +0 -0
  87. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ifreqt2.py +0 -0
  88. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/igammatone.py +0 -0
  89. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ignorm.py +0 -0
  90. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/imglsadf.py +0 -0
  91. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/imsvq.py +0 -0
  92. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/interpolate.py +0 -0
  93. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ipnorm.py +0 -0
  94. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ipqmf.py +0 -0
  95. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/is2par.py +0 -0
  96. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/iulaw.py +0 -0
  97. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ivq.py +0 -0
  98. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lar2par.py +0 -0
  99. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/levdur.py +0 -0
  100. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/linear_intpl.py +0 -0
  101. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lpc2lsp.py +0 -0
  102. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lpc2par.py +0 -0
  103. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lpccheck.py +0 -0
  104. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lsp2lpc.py +0 -0
  105. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lsp2sp.py +0 -0
  106. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/lspcheck.py +0 -0
  107. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/magic_intpl.py +0 -0
  108. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mc2b.py +0 -0
  109. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mgcep.py +0 -0
  110. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mlpg.py +0 -0
  111. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mlsacheck.py +0 -0
  112. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/mpir2c.py +0 -0
  113. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/msvq.py +0 -0
  114. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ndps2c.py +0 -0
  115. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/nmf.py +0 -0
  116. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/norm0.py +0 -0
  117. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/par2is.py +0 -0
  118. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/par2lar.py +0 -0
  119. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/par2lpc.py +0 -0
  120. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/pca.py +0 -0
  121. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/phase.py +0 -0
  122. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/pitch.py +0 -0
  123. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/pol_root.py +0 -0
  124. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/poledf.py +0 -0
  125. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/pqmf.py +0 -0
  126. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/quantize.py +0 -0
  127. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/rlevdur.py +0 -0
  128. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/rmse.py +0 -0
  129. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/root_pol.py +0 -0
  130. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/snr.py +0 -0
  131. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/ulaw.py +0 -0
  132. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/vq.py +0 -0
  133. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/wht.py +0 -0
  134. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/yingram.py +0 -0
  135. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/zcross.py +0 -0
  136. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/modules/zerodf.py +0 -0
  137. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/signals.py +0 -0
  138. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/librosa/LICENSE +0 -0
  139. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/librosa/__init__.py +0 -0
  140. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/world/LICENSE +0 -0
  141. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/third_party/world/__init__.py +0 -0
  142. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/typing.py +0 -0
  143. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/utils/__init__.py +0 -0
  144. {diffsptk-3.0.2 → diffsptk-3.2.0}/diffsptk/utils/public.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diffsptk
3
- Version: 3.0.2
3
+ Version: 3.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/
@@ -47,11 +47,11 @@ Description-Content-Type: text/markdown
47
47
 
48
48
  *diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
49
49
 
50
- [![Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/3.0.2/)
50
+ [![Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/3.2.0/)
51
51
  [![Downloads](https://static.pepy.tech/badge/diffsptk)](https://pepy.tech/project/diffsptk)
52
52
  [![ClickPy](https://img.shields.io/badge/downloads-clickpy-yellow.svg)](https://clickpy.clickhouse.com/dashboard/diffsptk)
53
53
  [![Python Version](https://img.shields.io/pypi/pyversions/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
54
- [![PyTorch Version](https://img.shields.io/badge/pytorch-2.3.1%20%7C%202.6.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
54
+ [![PyTorch Version](https://img.shields.io/badge/pytorch-2.3.1%20%7C%202.7.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
55
55
  [![PyPI Version](https://img.shields.io/pypi/v/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
56
56
  [![Codecov](https://codecov.io/gh/sp-nitech/diffsptk/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sp-nitech/diffsptk)
57
57
  [![License](https://img.shields.io/github/license/sp-nitech/diffsptk.svg)](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
@@ -65,7 +65,7 @@ Description-Content-Type: text/markdown
65
65
 
66
66
  ## Documentation
67
67
 
68
- - See [this page](https://sp-nitech.github.io/diffsptk/3.0.2/) for the reference manual.
68
+ - See [this page](https://sp-nitech.github.io/diffsptk/3.2.0/) for the reference manual.
69
69
  - Our [paper](https://www.isca-speech.org/archive/ssw_2023/yoshimura23_ssw.html) is available on the ISCA Archive.
70
70
 
71
71
  ## Installation
@@ -167,7 +167,7 @@ diffsptk.write("voiced.wav", x_voiced, sr)
167
167
  diffsptk.write("unvoiced.wav", x_unvoiced, sr)
168
168
  ```
169
169
 
170
- ### WORLD analysis and mel-cepstral synthesis
170
+ ### WORLD analysis and synthesis
171
171
 
172
172
  ```python
173
173
  import diffsptk
@@ -208,26 +208,15 @@ pitch_spec = diffsptk.PitchAdaptiveSpectralAnalysis(
208
208
  algorithm="cheap-trick",
209
209
  out_format="power",
210
210
  )
211
- H = pitch_spec(x, f0)
211
+ S = pitch_spec(x, f0)
212
212
 
213
- # Estimate mel-cepstrum of x.
214
- alpha = diffsptk.get_alpha(sr)
215
- mcep = diffsptk.MelCepstralAnalysis(fft_length=n_fft, cep_order=M, alpha=alpha)
216
- mc_a = mcep(A)
217
- mc_h = mcep(H)
218
-
219
- # Generate excitation signals.
220
- excite = diffsptk.ExcitationGeneration(frame_period=fp, unvoiced_region="zeros")
221
- p = (sr / f0).nan_to_num(posinf=0)
222
- pulse = excite(p)
223
- noise = diffsptk.nrand(len(pulse) - 1)
224
-
225
- # Make mixed excitation signal and reconstruct x.
226
- mlsa = diffsptk.MLSA(filter_order=M, frame_period=fp, alpha=alpha, taylor_order=20)
227
- e_p = pulse - mlsa(pulse, mc_a)
228
- e_a = mlsa(noise, mc_a)
229
- e = e_p + e_a
230
- x_hat = mlsa(e, mc_h)
213
+ # Reconstruct x.
214
+ world_synth = diffsptk.WorldSynthesis(
215
+ frame_period=fp,
216
+ sample_rate=sr,
217
+ fft_length=n_fft,
218
+ )
219
+ x_hat = world_synth(f0, A, S)
231
220
 
232
221
  # Write reconstructed waveform.
233
222
  diffsptk.write("reconst.wav", x_hat, sr)
@@ -2,11 +2,11 @@
2
2
 
3
3
  *diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
4
4
 
5
- [![Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/3.0.2/)
5
+ [![Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/3.2.0/)
6
6
  [![Downloads](https://static.pepy.tech/badge/diffsptk)](https://pepy.tech/project/diffsptk)
7
7
  [![ClickPy](https://img.shields.io/badge/downloads-clickpy-yellow.svg)](https://clickpy.clickhouse.com/dashboard/diffsptk)
8
8
  [![Python Version](https://img.shields.io/pypi/pyversions/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
9
- [![PyTorch Version](https://img.shields.io/badge/pytorch-2.3.1%20%7C%202.6.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
9
+ [![PyTorch Version](https://img.shields.io/badge/pytorch-2.3.1%20%7C%202.7.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
10
10
  [![PyPI Version](https://img.shields.io/pypi/v/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
11
11
  [![Codecov](https://codecov.io/gh/sp-nitech/diffsptk/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sp-nitech/diffsptk)
12
12
  [![License](https://img.shields.io/github/license/sp-nitech/diffsptk.svg)](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
@@ -20,7 +20,7 @@
20
20
 
21
21
  ## Documentation
22
22
 
23
- - See [this page](https://sp-nitech.github.io/diffsptk/3.0.2/) for the reference manual.
23
+ - See [this page](https://sp-nitech.github.io/diffsptk/3.2.0/) for the reference manual.
24
24
  - Our [paper](https://www.isca-speech.org/archive/ssw_2023/yoshimura23_ssw.html) is available on the ISCA Archive.
25
25
 
26
26
  ## Installation
@@ -122,7 +122,7 @@ diffsptk.write("voiced.wav", x_voiced, sr)
122
122
  diffsptk.write("unvoiced.wav", x_unvoiced, sr)
123
123
  ```
124
124
 
125
- ### WORLD analysis and mel-cepstral synthesis
125
+ ### WORLD analysis and synthesis
126
126
 
127
127
  ```python
128
128
  import diffsptk
@@ -163,26 +163,15 @@ pitch_spec = diffsptk.PitchAdaptiveSpectralAnalysis(
163
163
  algorithm="cheap-trick",
164
164
  out_format="power",
165
165
  )
166
- H = pitch_spec(x, f0)
166
+ S = pitch_spec(x, f0)
167
167
 
168
- # Estimate mel-cepstrum of x.
169
- alpha = diffsptk.get_alpha(sr)
170
- mcep = diffsptk.MelCepstralAnalysis(fft_length=n_fft, cep_order=M, alpha=alpha)
171
- mc_a = mcep(A)
172
- mc_h = mcep(H)
173
-
174
- # Generate excitation signals.
175
- excite = diffsptk.ExcitationGeneration(frame_period=fp, unvoiced_region="zeros")
176
- p = (sr / f0).nan_to_num(posinf=0)
177
- pulse = excite(p)
178
- noise = diffsptk.nrand(len(pulse) - 1)
179
-
180
- # Make mixed excitation signal and reconstruct x.
181
- mlsa = diffsptk.MLSA(filter_order=M, frame_period=fp, alpha=alpha, taylor_order=20)
182
- e_p = pulse - mlsa(pulse, mc_a)
183
- e_a = mlsa(noise, mc_a)
184
- e = e_p + e_a
185
- x_hat = mlsa(e, mc_h)
168
+ # Reconstruct x.
169
+ world_synth = diffsptk.WorldSynthesis(
170
+ frame_period=fp,
171
+ sample_rate=sr,
172
+ fft_length=n_fft,
173
+ )
174
+ x_hat = world_synth(f0, A, S)
186
175
 
187
176
  # Write reconstructed waveform.
188
177
  diffsptk.write("reconst.wav", x_hat, sr)
@@ -593,6 +593,7 @@ def fbank(
593
593
  f_min: float = 0,
594
594
  f_max: float | None = None,
595
595
  floor: float = 1e-5,
596
+ gamma: float = 0,
596
597
  use_power: bool = False,
597
598
  out_format: str = "y",
598
599
  ) -> tuple[Tensor, Tensor] | Tensor:
@@ -618,6 +619,9 @@ def fbank(
618
619
  floor : float > 0
619
620
  The minimum mel filter bank output in linear scale.
620
621
 
622
+ gamma : float in [-1, 1]
623
+ The parameter of the generalized logarithmic function.
624
+
621
625
  use_power : bool
622
626
  If True, use the power spectrum instead of the amplitude spectrum.
623
627
 
@@ -641,6 +645,7 @@ def fbank(
641
645
  f_min=f_min,
642
646
  f_max=f_max,
643
647
  floor=floor,
648
+ gamma=gamma,
644
649
  use_power=use_power,
645
650
  out_format=out_format,
646
651
  )
@@ -672,6 +677,33 @@ def fftcep(x: Tensor, cep_order: int, accel: float = 0, n_iter: int = 0) -> Tens
672
677
  return nn.CepstralAnalysis._func(x, cep_order=cep_order, accel=accel, n_iter=n_iter)
673
678
 
674
679
 
680
+ def fftr(
681
+ x: Tensor, fft_length: int | None = None, out_format: str = "complex"
682
+ ) -> Tensor:
683
+ """Compute FFT of a real signal.
684
+
685
+ Parameters
686
+ ----------
687
+ x : Tensor [shape=(..., N)]
688
+ The real input signal.
689
+
690
+ fft_length : int >= 2 or None
691
+ The FFT length, :math:`L`.
692
+
693
+ out_format : ['complex', 'real', 'imaginary', 'amplitude', 'power']
694
+ The output format.
695
+
696
+ Returns
697
+ -------
698
+ out : Tensor [shape=(..., L/2+1)]
699
+ The output spectrum.
700
+
701
+ """
702
+ return nn.RealValuedFastFourierTransform._func(
703
+ x, fft_length=fft_length, out_format=out_format
704
+ )
705
+
706
+
675
707
  def flux(
676
708
  x: Tensor,
677
709
  y: Tensor | None = None,
@@ -832,6 +864,101 @@ def gnorm(x: Tensor, gamma: float = 0, c: int | None = None) -> Tensor:
832
864
  return nn.GeneralizedCepstrumGainNormalization._func(x, gamma=gamma, c=c)
833
865
 
834
866
 
867
+ def griffin(
868
+ y: Tensor,
869
+ *,
870
+ out_length: int | None = None,
871
+ frame_length: int = 400,
872
+ frame_period: int = 80,
873
+ fft_length: int = 512,
874
+ center: bool = True,
875
+ mode: str = "constant",
876
+ window: str = "blackman",
877
+ norm: str = "power",
878
+ symmetric: bool = True,
879
+ n_iter: int = 100,
880
+ alpha: float = 0.99,
881
+ beta: float = 0.99,
882
+ gamma: float = 1.1,
883
+ init_phase: str = "random",
884
+ verbose: bool = False,
885
+ ) -> Tensor:
886
+ """Reconstruct a waveform from the spectrum using the Griffin-Lim algorithm.
887
+
888
+ Parameters
889
+ ----------
890
+ y : Tensor [shape=(..., T/P, N/2+1)]
891
+ The power spectrum.
892
+
893
+ out_length : int > 0 or None
894
+ The length of the output waveform.
895
+
896
+ frame_length : int >= 1
897
+ The frame length in samples, :math:`L`.
898
+
899
+ frame_period : int >= 1
900
+ The frame period in samples, :math:`P`.
901
+
902
+ fft_length : int >= L
903
+ The number of FFT bins, :math:`N`.
904
+
905
+ center : bool
906
+ If True, pad the input on both sides so that the frame is centered.
907
+
908
+ window : ['blackman', 'hamming', 'hanning', 'bartlett', 'trapezoidal', \
909
+ 'rectangular', 'nuttall']
910
+ The window type.
911
+
912
+ norm : ['none', 'power', 'magnitude']
913
+ The normalization type of the window.
914
+
915
+ symmetric : bool
916
+ If True, the window is symmetric, otherwise periodic.
917
+
918
+ n_iter : int >= 1
919
+ The number of iterations for phase reconstruction.
920
+
921
+ alpha : float >= 0
922
+ The momentum factor, :math:`\\alpha`.
923
+
924
+ beta : float >= 0
925
+ The momentum factor, :math:`\\beta`.
926
+
927
+ gamma : float >= 0
928
+ The smoothing factor, :math:`\\gamma`.
929
+
930
+ init_phase : ['zeros', 'random']
931
+ The initial phase for the reconstruction.
932
+
933
+ verbose : bool
934
+ If True, print the SNR at each iteration.
935
+
936
+ Returns
937
+ -------
938
+ out : Tensor [shape=(..., T)]
939
+ The reconstructed waveform.
940
+
941
+ """
942
+ return nn.GriffinLim._func(
943
+ y,
944
+ out_length=out_length,
945
+ frame_length=frame_length,
946
+ frame_period=frame_period,
947
+ fft_length=fft_length,
948
+ center=center,
949
+ mode=mode,
950
+ window=window,
951
+ norm=norm,
952
+ symmetric=symmetric,
953
+ n_iter=n_iter,
954
+ alpha=alpha,
955
+ beta=beta,
956
+ gamma=gamma,
957
+ init_phase=init_phase,
958
+ verbose=verbose,
959
+ )
960
+
961
+
835
962
  def grpdelay(
836
963
  b: Tensor | None = None,
837
964
  a: Tensor | None = None,
@@ -1051,6 +1178,26 @@ def idst(y: Tensor, dst_type: int = 2) -> Tensor:
1051
1178
  return nn.InverseDiscreteSineTransform._func(y, dst_type=dst_type)
1052
1179
 
1053
1180
 
1181
+ def ifftr(y: Tensor, out_length: int | None = None) -> Tensor:
1182
+ """Compute inverse FFT of a complex spectrum.
1183
+
1184
+ Parameters
1185
+ ----------
1186
+ y : Tensor [shape=(..., L/2+1)]
1187
+ The complex input spectrum.
1188
+
1189
+ out_length : int or None
1190
+ The output length, :math:`N`.
1191
+
1192
+ Returns
1193
+ -------
1194
+ out : Tensor [shape=(..., N)]
1195
+ The real output signal.
1196
+
1197
+ """
1198
+ return nn.RealValuedInverseFastFourierTransform._func(y, out_length=out_length)
1199
+
1200
+
1054
1201
  def ifreqt2(
1055
1202
  c: Tensor, out_order: int, alpha: float = 0, theta: float = 0, n_fft: int = 512
1056
1203
  ) -> Tensor:
@@ -1059,7 +1206,7 @@ def ifreqt2(
1059
1206
  Parameters
1060
1207
  ----------
1061
1208
  c : Tensor [shape=(..., M1+1)]
1062
- Cepstral coefficients.
1209
+ The cepstral coefficients.
1063
1210
 
1064
1211
  out_order : int >= 0
1065
1212
  The order of the output sequence, :math:`M_2`.
@@ -1243,6 +1390,7 @@ def istft(
1243
1390
  center: bool = True,
1244
1391
  window: str = "blackman",
1245
1392
  norm: str = "power",
1393
+ symmetric: bool = True,
1246
1394
  ) -> Tensor:
1247
1395
  """Compute inverse short-time Fourier transform.
1248
1396
 
@@ -1273,6 +1421,9 @@ def istft(
1273
1421
  norm : ['none', 'power', 'magnitude']
1274
1422
  The normalization type of the window.
1275
1423
 
1424
+ symmetric : bool
1425
+ If True, the window is symmetric, otherwise periodic.
1426
+
1276
1427
  Returns
1277
1428
  -------
1278
1429
  out : Tensor [shape=(..., T)]
@@ -1288,6 +1439,7 @@ def istft(
1288
1439
  center=center,
1289
1440
  window=window,
1290
1441
  norm=norm,
1442
+ symmetric=symmetric,
1291
1443
  )
1292
1444
 
1293
1445
 
@@ -1766,6 +1918,7 @@ def mfcc(
1766
1918
  f_min: float = 0,
1767
1919
  f_max: float | None = None,
1768
1920
  floor: float = 1e-5,
1921
+ gamma: float = 0,
1769
1922
  out_format: str = "y",
1770
1923
  ) -> Tensor:
1771
1924
  """Compute the MFCC from the power spectrum.
@@ -1796,6 +1949,9 @@ def mfcc(
1796
1949
  floor : float > 0
1797
1950
  The minimum mel filter bank output in linear scale.
1798
1951
 
1952
+ gamma : float in [-1, 1]
1953
+ The parameter of the generalized logarithmic function.
1954
+
1799
1955
  out_format : ['y', 'yE', 'yc', 'ycE']
1800
1956
  `y` is MFCC, `c` is C0, and `E` is energy.
1801
1957
 
@@ -1820,6 +1976,7 @@ def mfcc(
1820
1976
  f_min=f_min,
1821
1977
  f_max=f_max,
1822
1978
  floor=floor,
1979
+ gamma=gamma,
1823
1980
  out_format=out_format,
1824
1981
  )
1825
1982
 
@@ -2202,6 +2359,7 @@ def plp(
2202
2359
  f_min: float = 0,
2203
2360
  f_max: float | None = None,
2204
2361
  floor: float = 1e-5,
2362
+ gamma: float = 0,
2205
2363
  n_fft: int = 512,
2206
2364
  out_format: str = "y",
2207
2365
  ) -> Tensor:
@@ -2236,6 +2394,9 @@ def plp(
2236
2394
  floor : float > 0
2237
2395
  The minimum mel filter bank output in linear scale.
2238
2396
 
2397
+ gamma : float in [-1, 1]
2398
+ The parameter of the generalized logarithmic function.
2399
+
2239
2400
  n_fft : int >> M
2240
2401
  The number of FFT bins for the conversion from LPC to cepstrum.
2241
2402
 
@@ -2264,6 +2425,7 @@ def plp(
2264
2425
  f_min=f_min,
2265
2426
  f_max=f_max,
2266
2427
  floor=floor,
2428
+ gamma=gamma,
2267
2429
  n_fft=n_fft,
2268
2430
  out_format=out_format,
2269
2431
  )
@@ -2593,6 +2755,7 @@ def stft(
2593
2755
  mode: str = "constant",
2594
2756
  window: str = "blackman",
2595
2757
  norm: str = "power",
2758
+ symmetric: bool = True,
2596
2759
  eps: float = 1e-9,
2597
2760
  relative_floor: float | None = None,
2598
2761
  out_format: str = "power",
@@ -2629,6 +2792,9 @@ def stft(
2629
2792
  norm : ['none', 'power', 'magnitude']
2630
2793
  The normalization type of the window.
2631
2794
 
2795
+ symmetric : bool
2796
+ If True, the window is symmetric, otherwise periodic.
2797
+
2632
2798
  eps : float >= 0
2633
2799
  A small value added to the power spectrum.
2634
2800
 
@@ -2654,6 +2820,7 @@ def stft(
2654
2820
  mode=mode,
2655
2821
  window=window,
2656
2822
  norm=norm,
2823
+ symmetric=symmetric,
2657
2824
  eps=eps,
2658
2825
  relative_floor=relative_floor,
2659
2826
  out_format=out_format,
@@ -2691,6 +2858,7 @@ def unframe(
2691
2858
  center: bool = True,
2692
2859
  window: str = "rectangular",
2693
2860
  norm: str = "none",
2861
+ symmetric: bool = True,
2694
2862
  ) -> Tensor:
2695
2863
  """Revert framed waveform.
2696
2864
 
@@ -2715,6 +2883,9 @@ def unframe(
2715
2883
  norm : ['none', 'power', 'magnitude']
2716
2884
  The normalization type of the window.
2717
2885
 
2886
+ symmetric : bool
2887
+ If True, the window is symmetric, otherwise periodic.
2888
+
2718
2889
  Returns
2719
2890
  -------
2720
2891
  out : Tensor [shape=(..., T)]
@@ -2728,6 +2899,7 @@ def unframe(
2728
2899
  center=center,
2729
2900
  window=window,
2730
2901
  norm=norm,
2902
+ symmetric=symmetric,
2731
2903
  )
2732
2904
 
2733
2905
 
@@ -2757,6 +2929,7 @@ def window(
2757
2929
  *,
2758
2930
  window: str = "blackman",
2759
2931
  norm: str = "power",
2932
+ symmetric: bool = True,
2760
2933
  ) -> Tensor:
2761
2934
  """Apply a window function to the given waveform.
2762
2935
 
@@ -2776,13 +2949,18 @@ def window(
2776
2949
  norm : ['none', 'power', 'magnitude']
2777
2950
  The normalization type of the window.
2778
2951
 
2952
+ symmetric : bool
2953
+ If True, the window is symmetric, otherwise periodic.
2954
+
2779
2955
  Returns
2780
2956
  -------
2781
2957
  out : Tensor [shape=(..., L2)]
2782
2958
  The windowed waveform.
2783
2959
 
2784
2960
  """
2785
- return nn.Window._func(x, out_length=out_length, window=window, norm=norm)
2961
+ return nn.Window._func(
2962
+ x, out_length=out_length, window=window, norm=norm, symmetric=symmetric
2963
+ )
2786
2964
 
2787
2965
 
2788
2966
  def yingram(
@@ -47,6 +47,7 @@ from .excite import ExcitationGeneration
47
47
  from .fbank import MelFilterBankAnalysis
48
48
  from .fbank import MelFilterBankAnalysis as FBANK
49
49
  from .fftcep import CepstralAnalysis
50
+ from .fftr import RealValuedFastFourierTransform
50
51
  from .flux import Flux
51
52
  from .frame import Frame
52
53
  from .freqt import FrequencyTransform
@@ -55,6 +56,7 @@ from .gammatone import GammatoneFilterBankAnalysis
55
56
  from .gmm import GaussianMixtureModeling
56
57
  from .gmm import GaussianMixtureModeling as GMM
57
58
  from .gnorm import GeneralizedCepstrumGainNormalization
59
+ from .griffin import GriffinLim
58
60
  from .grpdelay import GroupDelay
59
61
  from .hilbert import HilbertTransform
60
62
  from .hilbert2 import TwoDimensionalHilbertTransform
@@ -70,6 +72,7 @@ from .idht import InverseDiscreteHartleyTransform
70
72
  from .idht import InverseDiscreteHartleyTransform as IDHT
71
73
  from .idst import InverseDiscreteSineTransform
72
74
  from .idst import InverseDiscreteSineTransform as IDST
75
+ from .ifftr import RealValuedInverseFastFourierTransform
73
76
  from .ifreqt2 import SecondOrderAllPassInverseFrequencyTransform
74
77
  from .igammatone import GammatoneFilterBankSynthesis
75
78
  from .ignorm import GeneralizedCepstrumInverseGainNormalization
@@ -160,6 +163,7 @@ from .wht import WalshHadamardTransform as WHT
160
163
  from .wht import WalshHadamardTransform as InverseWalshHadamardTransform
161
164
  from .wht import WalshHadamardTransform as IWHT
162
165
  from .window import Window
166
+ from .world_synth import WorldSynthesis
163
167
  from .yingram import Yingram
164
168
  from .zcross import ZeroCrossingAnalysis
165
169
  from .zerodf import AllZeroDigitalFilter
@@ -137,16 +137,10 @@ class Aperiodicity(BaseNonFunctionalModule):
137
137
  >>> f0 = pitch(x)
138
138
  >>> f0.shape
139
139
  torch.Size([7])
140
- >>> aperiodicity = diffsptk.Aperiodicity(160, 16000, 8)
140
+ >>> aperiodicity = diffsptk.Aperiodicity(160, 16000, 1024)
141
141
  >>> ap = aperiodicity(x, f0)
142
- >>> ap
143
- tensor([[0.1010, 0.9948, 0.9990, 0.9990, 0.9990],
144
- [0.0010, 0.8419, 0.3644, 0.5912, 0.9590],
145
- [0.0010, 0.5316, 0.3091, 0.5430, 0.9540],
146
- [0.0010, 0.3986, 0.1930, 0.4222, 0.9234],
147
- [0.0010, 0.3627, 0.1827, 0.4106, 0.9228],
148
- [0.0010, 0.3699, 0.1827, 0.4106, 0.9228],
149
- [0.0010, 0.7659, 0.7081, 0.8378, 0.9912]])
142
+ >>> ap.shape
143
+ torch.Size([7, 513])
150
144
 
151
145
  """
152
146
  d = x.dim()
@@ -53,7 +53,7 @@ class InfiniteImpulseResponseDigitalFilter(BaseFunctionalModule):
53
53
  ) -> None:
54
54
  super().__init__()
55
55
 
56
- _, _, tensors = self._precompute(*get_values(locals()))
56
+ _, _, tensors = self._precompute(*get_values(locals(), drop=1))
57
57
  if learnable and b is not None:
58
58
  self.b = nn.Parameter(tensors[0])
59
59
  else:
@@ -74,7 +74,7 @@ class DynamicRangeCompression(BaseFunctionalModule):
74
74
  ) -> None:
75
75
  super().__init__()
76
76
 
77
- self.values, _, tensors = self._precompute(*get_values(locals()))
77
+ self.values, _, tensors = self._precompute(*get_values(locals(), drop=1))
78
78
  if learnable:
79
79
  self.params = nn.Parameter(tensors[0])
80
80
  else:
@@ -16,6 +16,7 @@
16
16
 
17
17
  import numpy as np
18
18
  import torch
19
+ from torch import nn
19
20
 
20
21
  from ..typing import Callable, Precomputed
21
22
  from ..utils.private import check_size, get_values, to
@@ -46,6 +47,9 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
46
47
  floor : float > 0
47
48
  The minimum mel filter bank output in linear scale.
48
49
 
50
+ gamma : float in [-1, 1]
51
+ The parameter of the generalized logarithmic function.
52
+
49
53
  use_power : bool
50
54
  If True, use the power spectrum instead of the amplitude spectrum.
51
55
 
@@ -53,6 +57,9 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
53
57
  `y` is mel filber bank output and `E` is energy. If this is `yE`, the two output
54
58
  tensors are concatenated and return the tensor instead of the tuple.
55
59
 
60
+ learnable : bool
61
+ Whether to make the basis learnable.
62
+
56
63
  References
57
64
  ----------
58
65
  .. [1] S. Young et al., "The HTK Book," *Cambridge University Press*, 2006.
@@ -68,15 +75,20 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
68
75
  f_min: float = 0,
69
76
  f_max: float | None = None,
70
77
  floor: float = 1e-5,
78
+ gamma: float = 0,
71
79
  use_power: bool = False,
72
80
  out_format: str | int = "y",
81
+ learnable: bool = False,
73
82
  ) -> None:
74
83
  super().__init__()
75
84
 
76
85
  self.in_dim = fft_length // 2 + 1
77
86
 
78
- self.values, _, tensors = self._precompute(*get_values(locals()))
79
- self.register_buffer("H", tensors[0])
87
+ self.values, _, tensors = self._precompute(*get_values(locals(), drop=1))
88
+ if learnable:
89
+ self.H = nn.Parameter(tensors[0])
90
+ else:
91
+ self.register_buffer("H", tensors[0])
80
92
 
81
93
  def forward(
82
94
  self, x: torch.Tensor
@@ -110,7 +122,7 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
110
122
 
111
123
  """
112
124
  check_size(x.size(-1), self.in_dim, "dimension of spectrum")
113
- return self._forward(x, *self.values, **self._buffers)
125
+ return self._forward(x, *self.values, **self._buffers, **self._parameters)
114
126
 
115
127
  @staticmethod
116
128
  def _func(
@@ -133,6 +145,7 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
133
145
  f_min: float,
134
146
  f_max: float | None,
135
147
  floor: float,
148
+ gamma: float,
136
149
  ) -> None:
137
150
  if fft_length <= 1:
138
151
  raise ValueError("fft_length must be greater than 1.")
@@ -146,6 +159,8 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
146
159
  raise ValueError("Invalid f_min and f_max.")
147
160
  if floor <= 0:
148
161
  raise ValueError("floor must be positive.")
162
+ if 1 < abs(gamma):
163
+ raise ValueError("gamma must be in [-1, 1].")
149
164
 
150
165
  @staticmethod
151
166
  def _precompute(
@@ -155,6 +170,7 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
155
170
  f_min: float,
156
171
  f_max: float | None,
157
172
  floor: float,
173
+ gamma: float,
158
174
  use_power: bool,
159
175
  out_format: str | int,
160
176
  device: torch.device | None = None,
@@ -167,6 +183,7 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
167
183
  f_min,
168
184
  f_max,
169
185
  floor,
186
+ gamma,
170
187
  )
171
188
 
172
189
  if out_format in (0, "y"):
@@ -211,19 +228,21 @@ class MelFilterBankAnalysis(BaseFunctionalModule):
211
228
  if m < n_channel:
212
229
  weights[k, m] += 1 - w
213
230
 
214
- return (floor, use_power, formatter), None, (to(weights, dtype=dtype),)
231
+ return (floor, gamma, use_power, formatter), None, (to(weights, dtype=dtype),)
215
232
 
216
233
  @staticmethod
217
234
  def _forward(
218
235
  x: torch.Tensor,
219
236
  floor: float,
237
+ gamma: float,
220
238
  use_power: bool,
221
239
  formatter: Callable,
222
240
  H: torch.Tensor,
223
241
  ) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]:
224
242
  y = x if use_power else torch.sqrt(x)
225
243
  y = torch.matmul(y, H)
226
- y = torch.log(torch.clip(y, min=floor))
244
+ y = torch.clip(y, min=floor)
245
+ y = torch.log(y) if gamma == 0 else (torch.pow(x, gamma) - 1) / gamma
227
246
  E = (2 * x[..., 1:-1]).sum(-1) + x[..., 0] + x[..., -1]
228
247
  E = torch.log(E / (2 * (x.size(-1) - 1))).unsqueeze(-1)
229
248
  return formatter(y, E)