neverlib 0.2.8__py3-none-any.whl → 0.2.9__py3-none-any.whl

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 (430) hide show
  1. neverlib/QA/ImpactNoiseRejection.py +119 -0
  2. neverlib/QA/impact_noise_rejection.png +0 -0
  3. neverlib/QA/out.pcm +0 -0
  4. neverlib/QA/out.wav +0 -0
  5. neverlib/audio_aug/README.md +3 -0
  6. neverlib/audio_aug/__init__.py +0 -54
  7. neverlib/data_analyze/__init__.py +0 -44
  8. neverlib/filter/__init__.py +0 -23
  9. neverlib/filter/auto_eq/__init__.py +0 -36
  10. neverlib/filter/core.py +8 -5
  11. neverlib/metrics/README.md +35 -0
  12. neverlib/metrics/__init__.py +0 -36
  13. neverlib/metrics/pesq_c/PESQ +0 -0
  14. neverlib/signal_gen/babble_noise_generate.py +113 -0
  15. neverlib/tests/__init__.py +0 -17
  16. neverlib/utils/README.md +29 -0
  17. neverlib/utils/__init__.py +6 -50
  18. neverlib/utils/audio_split.py +20 -20
  19. neverlib/utils/checkGPU.py +52 -79
  20. neverlib/utils/floder.py +115 -0
  21. neverlib/utils/pcm.py +42 -0
  22. neverlib/utils/utils.py +3 -92
  23. neverlib/vad/__init__.py +0 -38
  24. {neverlib-0.2.8.dist-info → neverlib-0.2.9.dist-info}/METADATA +15 -1
  25. neverlib-0.2.9.dist-info/RECORD +119 -0
  26. neverlib/.claude/settings.local.json +0 -9
  27. neverlib/.history/Docs/audio_aug/del_20250827162530.py +0 -0
  28. neverlib/.history/Docs/audio_aug/del_20250827162540.py +0 -2
  29. neverlib/.history/Docs/audio_aug/del_20250827162541.py +0 -7
  30. neverlib/.history/Docs/audio_aug/del_20250827162606.py +0 -7
  31. neverlib/.history/Docs/audio_aug/del_20250827162637.py +0 -8
  32. neverlib/.history/Docs/audio_aug/del_20250827162645.py +0 -8
  33. neverlib/.history/Docs/audio_aug/del_20250827162723.py +0 -9
  34. neverlib/.history/Docs/audio_aug/del_20250827162739.py +0 -9
  35. neverlib/.history/Docs/audio_aug/test_snr_20250806011311.py +0 -0
  36. neverlib/.history/Docs/audio_aug/test_snr_20250806011331.py +0 -75
  37. neverlib/.history/Docs/audio_aug/test_snr_20250806011342.py +0 -57
  38. neverlib/.history/Docs/audio_aug/test_snr_20250806011352.py +0 -57
  39. neverlib/.history/Docs/audio_aug/test_snr_20250806011403.py +0 -57
  40. neverlib/.history/Docs/audio_aug/test_snr_20250806011413.py +0 -57
  41. neverlib/.history/Docs/audio_aug/test_snr_20250806011435.py +0 -55
  42. neverlib/.history/Docs/audio_aug/test_snr_20250827161751.py +0 -55
  43. neverlib/.history/Docs/audio_aug/test_snr_20250827161754.py +0 -55
  44. neverlib/.history/Docs/audio_aug/test_snr_20250827161833.py +0 -54
  45. neverlib/.history/Docs/audio_aug/test_snr_20250827162017.py +0 -56
  46. neverlib/.history/Docs/audio_aug/test_snr_20250827162021.py +0 -57
  47. neverlib/.history/Docs/audio_aug/test_snr_20250827162028.py +0 -57
  48. neverlib/.history/Docs/audio_aug/test_snr_20250827162033.py +0 -55
  49. neverlib/.history/Docs/audio_aug_test/del_20250827162738.py +0 -9
  50. neverlib/.history/Docs/audio_aug_test/del_20250827162819.py +0 -9
  51. neverlib/.history/Docs/audio_aug_test/del_20250827162830.py +0 -9
  52. neverlib/.history/Docs/audio_aug_test/del_20250827162846.py +0 -9
  53. neverlib/.history/Docs/audio_aug_test/del_20250827162851.py +0 -9
  54. neverlib/.history/Docs/audio_aug_test/del_20250827162903.py +0 -10
  55. neverlib/.history/Docs/audio_aug_test/del_20250827162921.py +0 -10
  56. neverlib/.history/Docs/audio_aug_test/del_20250827162926.py +0 -10
  57. neverlib/.history/Docs/audio_aug_test/del_20250827163030.py +0 -10
  58. neverlib/.history/Docs/audio_aug_test/del_20250827163032.py +0 -10
  59. neverlib/.history/Docs/vad/1_20250810032405.py +0 -0
  60. neverlib/.history/Docs/vad/1_20250810032417.py +0 -39
  61. neverlib/.history/QA/html2markdown_20250822234112.md +0 -0
  62. neverlib/.history/QA/html2markdown_20250822234140.py +0 -9
  63. neverlib/.history/QA/html2markdown_20250822234141.md +0 -9
  64. neverlib/.history/QA/html2markdown_20250822234159.py +0 -12
  65. neverlib/.history/QA/html2markdown_20250822234200.py +0 -17
  66. neverlib/.history/QA/html2markdown_20250822234236.py +0 -17
  67. neverlib/.history/QA/html2markdown_20250822234340.py +0 -14
  68. neverlib/.history/QA/html2markdown_20250822234522.py +0 -18
  69. neverlib/.history/QA/html2markdown_20250822234601.py +0 -20
  70. neverlib/.history/QA/html2markdown_20250822234615.py +0 -22
  71. neverlib/.history/QA/html2markdown_20250822234715.py +0 -28
  72. neverlib/.history/QA/html2markdown_20250822234720.py +0 -27
  73. neverlib/.history/QA/html2markdown_20250822234903.py +0 -27
  74. neverlib/.history/__init___20250805234212.py +0 -41
  75. neverlib/.history/__init___20250904102635.py +0 -39
  76. neverlib/.history/__init___20250904102836.py +0 -34
  77. neverlib/.history/__init___20250904102838.py +0 -39
  78. neverlib/.history/__init___20250904102851.py +0 -33
  79. neverlib/.history/audio_aug/audio_aug_20250806010451.py +0 -125
  80. neverlib/.history/audio_aug/audio_aug_20250806010750.py +0 -138
  81. neverlib/.history/audio_aug/audio_aug_20250806010759.py +0 -140
  82. neverlib/.history/audio_aug/audio_aug_20250806010803.py +0 -140
  83. neverlib/.history/audio_aug/audio_aug_20250806010809.py +0 -140
  84. neverlib/.history/audio_aug/audio_aug_20250806011108.py +0 -140
  85. neverlib/.history/audio_aug/audio_aug_20250826155913.py +0 -158
  86. neverlib/.history/audio_aug/audio_aug_20250826164159.py +0 -159
  87. neverlib/.history/audio_aug/audio_aug_20250826164217.py +0 -160
  88. neverlib/.history/audio_aug/audio_aug_20250826164408.py +0 -161
  89. neverlib/.history/audio_aug/audio_aug_20250826164423.py +0 -161
  90. neverlib/.history/audio_aug/audio_aug_20250826164529.py +0 -161
  91. neverlib/.history/audio_aug/audio_aug_20250826164824.py +0 -161
  92. neverlib/.history/audio_aug/audio_aug_20250826164932.py +0 -162
  93. neverlib/.history/audio_aug/audio_aug_20250826164947.py +0 -162
  94. neverlib/.history/audio_aug/audio_aug_20250826165403.py +0 -162
  95. neverlib/.history/audio_aug/audio_aug_20250826165421.py +0 -162
  96. neverlib/.history/audio_aug/audio_aug_20250826165509.py +0 -163
  97. neverlib/.history/audio_aug/audio_aug_20250826165702.py +0 -163
  98. neverlib/.history/audio_aug/audio_aug_20250826165732.py +0 -165
  99. neverlib/.history/audio_aug/audio_aug_20250826170041.py +0 -163
  100. neverlib/.history/audio_aug/audio_aug_20250826170105.py +0 -164
  101. neverlib/.history/audio_aug/audio_aug_20250826170154.py +0 -164
  102. neverlib/.history/audio_aug/audio_aug_20250826170220.py +0 -165
  103. neverlib/.history/audio_aug/audio_aug_20250826170221.py +0 -165
  104. neverlib/.history/audio_aug/audio_aug_20250826170228.py +0 -165
  105. neverlib/.history/audio_aug/audio_aug_20250826170231.py +0 -165
  106. neverlib/.history/audio_aug/audio_aug_20250826212001.py +0 -165
  107. neverlib/.history/audio_aug/audio_aug_20250826220038.py +0 -165
  108. neverlib/.history/audio_aug/audio_aug_20250826220133.py +0 -165
  109. neverlib/.history/audio_aug/audio_aug_20250826220148.py +0 -165
  110. neverlib/.history/audio_aug/audio_aug_20250826220154.py +0 -165
  111. neverlib/.history/audio_aug/audio_aug_20250826220156.py +0 -165
  112. neverlib/.history/audio_aug/audio_aug_20250826220314.py +0 -165
  113. neverlib/.history/audio_aug/audio_aug_20250826220343.py +0 -184
  114. neverlib/.history/audio_aug/audio_aug_20250826220345.py +0 -184
  115. neverlib/.history/audio_aug/audio_aug_20250826220349.py +0 -184
  116. neverlib/.history/audio_aug/audio_aug_20250826220429.py +0 -184
  117. neverlib/.history/audio_aug/audio_aug_20250826220447.py +0 -184
  118. neverlib/.history/audio_aug/audio_aug_20250826220601.py +0 -186
  119. neverlib/.history/audio_aug/audio_aug_20250826220638.py +0 -186
  120. neverlib/.history/audio_aug/audio_aug_20250826220641.py +0 -186
  121. neverlib/.history/audio_aug/audio_aug_20250826220647.py +0 -186
  122. neverlib/.history/audio_aug/audio_aug_20250826220653.py +0 -186
  123. neverlib/.history/audio_aug/audio_aug_20250826220655.py +0 -186
  124. neverlib/.history/audio_aug/audio_aug_20250826220731.py +0 -185
  125. neverlib/.history/audio_aug/audio_aug_20250826220739.py +0 -185
  126. neverlib/.history/audio_aug/audio_aug_20250826220747.py +0 -185
  127. neverlib/.history/audio_aug/audio_aug_20250826220801.py +0 -186
  128. neverlib/.history/audio_aug/audio_aug_20250826220822.py +0 -186
  129. neverlib/.history/audio_aug/audio_aug_20250826220901.py +0 -186
  130. neverlib/.history/audio_aug/audio_aug_20250826221107.py +0 -187
  131. neverlib/.history/audio_aug/audio_aug_20250826221310.py +0 -188
  132. neverlib/.history/audio_aug/audio_aug_20250826221353.py +0 -191
  133. neverlib/.history/audio_aug/audio_aug_20250826221821.py +0 -191
  134. neverlib/.history/audio_aug/audio_aug_20250826221838.py +0 -191
  135. neverlib/.history/audio_aug/audio_aug_20250826221906.py +0 -191
  136. neverlib/.history/audio_aug/audio_aug_20250826221930.py +0 -191
  137. neverlib/.history/audio_aug/audio_aug_20250826221939.py +0 -191
  138. neverlib/.history/audio_aug/audio_aug_20250826221955.py +0 -191
  139. neverlib/.history/audio_aug/audio_aug_20250826222008.py +0 -197
  140. neverlib/.history/audio_aug/audio_aug_20250826222017.py +0 -200
  141. neverlib/.history/audio_aug/audio_aug_20250826222046.py +0 -203
  142. neverlib/.history/audio_aug/audio_aug_20250826222105.py +0 -203
  143. neverlib/.history/audio_aug/audio_aug_20250826222206.py +0 -203
  144. neverlib/.history/audio_aug/audio_aug_20250826222302.py +0 -203
  145. neverlib/.history/audio_aug/audio_aug_20250826222336.py +0 -203
  146. neverlib/.history/audio_aug/audio_aug_20250826222455.py +0 -204
  147. neverlib/.history/audio_aug/audio_aug_20250826222526.py +0 -204
  148. neverlib/.history/audio_aug/audio_aug_20250826222541.py +0 -204
  149. neverlib/.history/audio_aug/audio_aug_20250826222624.py +0 -202
  150. neverlib/.history/audio_aug/audio_aug_20250826222714.py +0 -205
  151. neverlib/.history/audio_aug/audio_aug_20250826222820.py +0 -205
  152. neverlib/.history/audio_aug/audio_aug_20250826222827.py +0 -205
  153. neverlib/.history/audio_aug/audio_aug_20250826222927.py +0 -232
  154. neverlib/.history/audio_aug/audio_aug_20250826223009.py +0 -232
  155. neverlib/.history/audio_aug/audio_aug_20250826223054.py +0 -232
  156. neverlib/.history/audio_aug/audio_aug_20250826223225.py +0 -233
  157. neverlib/.history/audio_aug/audio_aug_20250826223344.py +0 -236
  158. neverlib/.history/audio_aug/audio_aug_20250826223356.py +0 -236
  159. neverlib/.history/audio_aug/audio_aug_20250826223955.py +0 -242
  160. neverlib/.history/audio_aug/audio_aug_20250826224210.py +0 -240
  161. neverlib/.history/audio_aug/audio_aug_20250826224250.py +0 -242
  162. neverlib/.history/audio_aug/audio_aug_20250826224323.py +0 -280
  163. neverlib/.history/audio_aug/audio_aug_20250826224452.py +0 -263
  164. neverlib/.history/audio_aug/audio_aug_20250826224455.py +0 -263
  165. neverlib/.history/audio_aug/audio_aug_20250826224502.py +0 -263
  166. neverlib/.history/audio_aug/audio_aug_20250826224528.py +0 -263
  167. neverlib/.history/audio_aug/audio_aug_20250826224658.py +0 -263
  168. neverlib/.history/audio_aug/audio_aug_20250826224833.py +0 -264
  169. neverlib/.history/audio_aug/audio_aug_20250826225013.py +0 -269
  170. neverlib/.history/audio_aug/audio_aug_20250826225050.py +0 -269
  171. neverlib/.history/audio_aug/audio_aug_20250826225241.py +0 -268
  172. neverlib/.history/audio_aug/audio_aug_20250826225315.py +0 -266
  173. neverlib/.history/audio_aug/audio_aug_20250826225404.py +0 -266
  174. neverlib/.history/audio_aug/audio_aug_20250826225502.py +0 -265
  175. neverlib/.history/audio_aug/audio_aug_20250826225950.py +0 -267
  176. neverlib/.history/audio_aug/audio_aug_20250826225959.py +0 -268
  177. neverlib/.history/audio_aug/audio_aug_20250826230222.py +0 -271
  178. neverlib/.history/audio_aug/audio_aug_20250826230248.py +0 -270
  179. neverlib/.history/audio_aug/audio_aug_20250826230638.py +0 -266
  180. neverlib/.history/audio_aug/audio_aug_20250826230755.py +0 -266
  181. neverlib/.history/audio_aug/audio_aug_20250826230941.py +0 -265
  182. neverlib/.history/audio_aug/audio_aug_20250826231054.py +0 -266
  183. neverlib/.history/audio_aug/audio_aug_20250826231117.py +0 -266
  184. neverlib/.history/audio_aug/audio_aug_20250826231219.py +0 -266
  185. neverlib/.history/audio_aug/audio_aug_20250826232330.py +0 -266
  186. neverlib/.history/audio_aug/audio_aug_20250826232352.py +0 -266
  187. neverlib/.history/audio_aug/audio_aug_20250827152748.py +0 -268
  188. neverlib/.history/audio_aug/audio_aug_20250827152806.py +0 -268
  189. neverlib/.history/audio_aug/audio_aug_20250827152808.py +0 -268
  190. neverlib/.history/audio_aug/audio_aug_20250827152917.py +0 -283
  191. neverlib/.history/audio_aug/audio_aug_20250827152929.py +0 -281
  192. neverlib/.history/audio_aug/audio_aug_20250827153100.py +0 -286
  193. neverlib/.history/audio_aug/audio_aug_20250827153102.py +0 -286
  194. neverlib/.history/audio_aug/audio_aug_20250827153301.py +0 -295
  195. neverlib/.history/audio_aug/audio_aug_20250827153331.py +0 -298
  196. neverlib/.history/audio_aug/audio_aug_20250827153525.py +0 -303
  197. neverlib/.history/audio_aug/audio_aug_20250827153533.py +0 -304
  198. neverlib/.history/audio_aug/audio_aug_20250827153541.py +0 -321
  199. neverlib/.history/audio_aug/audio_aug_20250827153805.py +0 -322
  200. neverlib/.history/audio_aug/audio_aug_20250827153832.py +0 -323
  201. neverlib/.history/audio_aug/audio_aug_20250827153836.py +0 -324
  202. neverlib/.history/audio_aug/audio_aug_20250827153846.py +0 -324
  203. neverlib/.history/audio_aug/audio_aug_20250827153859.py +0 -325
  204. neverlib/.history/audio_aug/audio_aug_20250827154453.py +0 -337
  205. neverlib/.history/audio_aug/audio_aug_20250827154513.py +0 -355
  206. neverlib/.history/audio_aug/audio_aug_20250827154538.py +0 -356
  207. neverlib/.history/audio_aug/audio_aug_20250827154541.py +0 -357
  208. neverlib/.history/audio_aug/audio_aug_20250827154612.py +0 -357
  209. neverlib/.history/audio_aug/audio_aug_20250827154657.py +0 -360
  210. neverlib/.history/audio_aug/audio_aug_20250827154708.py +0 -360
  211. neverlib/.history/audio_aug/audio_aug_20250827154728.py +0 -366
  212. neverlib/.history/audio_aug/audio_aug_20250827154755.py +0 -367
  213. neverlib/.history/audio_aug/audio_aug_20250827154800.py +0 -367
  214. neverlib/.history/audio_aug/audio_aug_20250827154917.py +0 -368
  215. neverlib/.history/audio_aug/audio_aug_20250827154928.py +0 -369
  216. neverlib/.history/audio_aug/audio_aug_20250827154932.py +0 -370
  217. neverlib/.history/audio_aug/audio_aug_20250827154947.py +0 -372
  218. neverlib/.history/audio_aug/audio_aug_20250827155015.py +0 -375
  219. neverlib/.history/audio_aug/audio_aug_20250827155106.py +0 -375
  220. neverlib/.history/audio_aug/audio_aug_20250827155114.py +0 -393
  221. neverlib/.history/audio_aug/audio_aug_20250827155207.py +0 -415
  222. neverlib/.history/audio_aug/audio_aug_20250827155300.py +0 -415
  223. neverlib/.history/audio_aug/audio_aug_20250827155321.py +0 -471
  224. neverlib/.history/audio_aug/audio_aug_20250827164703.py +0 -471
  225. neverlib/.history/audio_aug/audio_aug_20250827164749.py +0 -471
  226. neverlib/.history/audio_aug/audio_aug_20250827165252.py +0 -472
  227. neverlib/.history/audio_aug/audio_aug_20250827165334.py +0 -472
  228. neverlib/.history/audio_aug/audio_aug_20250827165404.py +0 -473
  229. neverlib/.history/audio_aug/audio_aug_20250827165610.py +0 -473
  230. neverlib/.history/audio_aug/audio_aug_20250827165805.py +0 -473
  231. neverlib/.history/audio_aug/audio_aug_20250827170056.py +0 -473
  232. neverlib/.history/audio_aug/audio_aug_20250827170106.py +0 -472
  233. neverlib/.history/audio_aug/audio_aug_20250827170143.py +0 -472
  234. neverlib/.history/audio_aug/audio_aug_20250827170216.py +0 -472
  235. neverlib/.history/audio_aug/audio_aug_20250827170218.py +0 -472
  236. neverlib/.history/audio_aug/audio_aug_20250827170314.py +0 -472
  237. neverlib/.history/audio_aug/audio_aug_20250827171500.py +0 -471
  238. neverlib/.history/audio_aug/audio_aug_20250827172347.py +0 -471
  239. neverlib/.history/audio_aug/audio_aug_20250827172558.py +0 -470
  240. neverlib/.history/audio_aug/audio_aug_20250827172559.py +0 -470
  241. neverlib/.history/audio_aug/audio_aug_20250827172801.py +0 -470
  242. neverlib/.history/audio_aug/audio_aug_20250827182522.py +0 -470
  243. neverlib/.history/audio_aug/audio_aug_20250827182526.py +0 -470
  244. neverlib/.history/audio_aug/audio_aug_20250827182626.py +0 -470
  245. neverlib/.history/audio_aug/audio_aug_20250827182715.py +0 -470
  246. neverlib/.history/audio_aug/audio_aug_20250904185444.py +0 -470
  247. neverlib/.history/audio_aug/audio_aug_20250904185538.py +0 -445
  248. neverlib/.history/dataAnalyze/__init___20250805234204.py +0 -87
  249. neverlib/.history/dataAnalyze/__init___20250806204125.py +0 -14
  250. neverlib/.history/dataAnalyze/__init___20250806204139.py +0 -14
  251. neverlib/.history/dataAnalyze/__init___20250806204159.py +0 -14
  252. neverlib/.history/data_analyze/__init___20250806204158.py +0 -14
  253. neverlib/.history/data_analyze/__init___20250827163248.py +0 -14
  254. neverlib/.history/filter/__init___20250820103351.py +0 -70
  255. neverlib/.history/filter/__init___20250821102348.py +0 -70
  256. neverlib/.history/filter/__init___20250821102405.py +0 -14
  257. neverlib/.history/filter/auto_eq/__init___20250819213121.py +0 -36
  258. neverlib/.history/filter/auto_eq/__init___20250821102241.py +0 -36
  259. neverlib/.history/filter/auto_eq/__init___20250821102259.py +0 -36
  260. neverlib/.history/filter/auto_eq/__init___20250821102307.py +0 -36
  261. neverlib/.history/filter/auto_eq/__init___20250821102310.py +0 -36
  262. neverlib/.history/filter/auto_eq/__init___20250821102318.py +0 -36
  263. neverlib/.history/filter/auto_eq/__init___20250821102507.py +0 -36
  264. neverlib/.history/filter/auto_eq/de_eq_20250820103848.py +0 -361
  265. neverlib/.history/filter/auto_eq/de_eq_20250821102422.py +0 -360
  266. neverlib/.history/filter/auto_eq/freq_eq_20250805234206.py +0 -75
  267. neverlib/.history/filter/auto_eq/freq_eq_20250820140732.py +0 -75
  268. neverlib/.history/filter/auto_eq/freq_eq_20250820140745.py +0 -75
  269. neverlib/.history/filter/auto_eq/freq_eq_20250820140816.py +0 -75
  270. neverlib/.history/filter/auto_eq/freq_eq_20250820140938.py +0 -77
  271. neverlib/.history/filter/auto_eq/freq_eq_20250820141003.py +0 -77
  272. neverlib/.history/filter/auto_eq/freq_eq_20250820141006.py +0 -77
  273. neverlib/.history/filter/auto_eq/freq_eq_20250820141019.py +0 -77
  274. neverlib/.history/filter/auto_eq/freq_eq_20250820141049.py +0 -77
  275. neverlib/.history/filter/auto_eq/freq_eq_20250820141211.py +0 -77
  276. neverlib/.history/filter/auto_eq/freq_eq_20250820141227.py +0 -77
  277. neverlib/.history/filter/auto_eq/freq_eq_20250820141311.py +0 -78
  278. neverlib/.history/filter/auto_eq/freq_eq_20250820141340.py +0 -78
  279. neverlib/.history/filter/auto_eq/freq_eq_20250820141712.py +0 -78
  280. neverlib/.history/filter/auto_eq/freq_eq_20250820141733.py +0 -78
  281. neverlib/.history/filter/auto_eq/freq_eq_20250820141755.py +0 -78
  282. neverlib/.history/filter/auto_eq/freq_eq_20250821102434.py +0 -76
  283. neverlib/.history/filter/auto_eq/freq_eq_20250821102500.py +0 -76
  284. neverlib/.history/filter/auto_eq/freq_eq_20250821102502.py +0 -76
  285. neverlib/.history/filter/auto_eq/freq_eq_20250821143140.py +0 -76
  286. neverlib/.history/filter/auto_eq/freq_eq_20250821153208.py +0 -76
  287. neverlib/.history/filter/auto_eq/freq_eq_20250821153214.py +0 -76
  288. neverlib/.history/filter/auto_eq/ga_eq_basic_20250820102957.py +0 -380
  289. neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113054.py +0 -380
  290. neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113150.py +0 -380
  291. neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113520.py +0 -385
  292. neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113525.py +0 -385
  293. neverlib/.history/filter/auto_eq/ga_eq_basic_20250821102212.py +0 -385
  294. neverlib/.history/filter/auto_eq/ga_eq_basic_20250901110521.py +0 -385
  295. neverlib/.history/filter/auto_eq/ga_eq_basic_20250901110652.py +0 -385
  296. neverlib/.history/filter/common_20250806002134.py +0 -37
  297. neverlib/.history/filter/common_20250821120448.py +0 -49
  298. neverlib/.history/filter/common_20250821120453.py +0 -49
  299. neverlib/.history/metrics/dnsmos_20250806001612.py +0 -160
  300. neverlib/.history/metrics/dnsmos_20250815180659.py +0 -160
  301. neverlib/.history/metrics/dnsmos_20250815180701.py +0 -158
  302. neverlib/.history/metrics/dnsmos_20250815181321.py +0 -154
  303. neverlib/.history/metrics/dnsmos_20250815181327.py +0 -154
  304. neverlib/.history/metrics/dnsmos_20250815181331.py +0 -154
  305. neverlib/.history/metrics/dnsmos_20250815181620.py +0 -154
  306. neverlib/.history/metrics/dnsmos_20250815181631.py +0 -154
  307. neverlib/.history/metrics/dnsmos_20250815181742.py +0 -154
  308. neverlib/.history/metrics/dnsmos_20250815181824.py +0 -153
  309. neverlib/.history/metrics/dnsmos_20250815181834.py +0 -153
  310. neverlib/.history/metrics/dnsmos_20250815181922.py +0 -153
  311. neverlib/.history/metrics/dnsmos_20250815182011.py +0 -147
  312. neverlib/.history/metrics/dnsmos_20250815182036.py +0 -144
  313. neverlib/.history/metrics/dnsmos_20250815182936.py +0 -143
  314. neverlib/.history/metrics/dnsmos_20250815182942.py +0 -143
  315. neverlib/.history/metrics/dnsmos_20250815183032.py +0 -137
  316. neverlib/.history/metrics/dnsmos_20250815183101.py +0 -144
  317. neverlib/.history/metrics/dnsmos_20250815183121.py +0 -144
  318. neverlib/.history/metrics/dnsmos_20250815183123.py +0 -143
  319. neverlib/.history/metrics/dnsmos_20250815183214.py +0 -143
  320. neverlib/.history/metrics/dnsmos_20250815183240.py +0 -143
  321. neverlib/.history/metrics/dnsmos_20250815183248.py +0 -144
  322. neverlib/.history/metrics/dnsmos_20250815183407.py +0 -142
  323. neverlib/.history/metrics/dnsmos_20250815183409.py +0 -142
  324. neverlib/.history/metrics/dnsmos_20250815183431.py +0 -142
  325. neverlib/.history/metrics/dnsmos_20250815183507.py +0 -140
  326. neverlib/.history/metrics/dnsmos_20250815183513.py +0 -139
  327. neverlib/.history/metrics/dnsmos_20250815183618.py +0 -139
  328. neverlib/.history/metrics/dnsmos_20250815183709.py +0 -140
  329. neverlib/.history/metrics/dnsmos_20250815183756.py +0 -137
  330. neverlib/.history/metrics/dnsmos_20250815183815.py +0 -128
  331. neverlib/.history/metrics/dnsmos_20250815183827.py +0 -129
  332. neverlib/.history/metrics/dnsmos_20250815183913.py +0 -117
  333. neverlib/.history/metrics/dnsmos_20250815183914.py +0 -117
  334. neverlib/.history/metrics/dnsmos_20250815184003.py +0 -118
  335. neverlib/.history/metrics/dnsmos_20250815184040.py +0 -118
  336. neverlib/.history/metrics/dnsmos_20250815184049.py +0 -118
  337. neverlib/.history/metrics/dnsmos_20250815184104.py +0 -117
  338. neverlib/.history/metrics/dnsmos_20250815184200.py +0 -117
  339. neverlib/.history/metrics/lpc_lsp_metric_20250816015944.py +0 -128
  340. neverlib/.history/metrics/lpc_lsp_metric_20250816020142.py +0 -128
  341. neverlib/.history/metrics/lpc_lsp_metric_20250816020156.py +0 -128
  342. neverlib/.history/metrics/lpc_lsp_metric_20250816020554.py +0 -130
  343. neverlib/.history/metrics/lpc_lsp_metric_20250816020600.py +0 -125
  344. neverlib/.history/metrics/lpc_lsp_metric_20250816020631.py +0 -120
  345. neverlib/.history/metrics/lpc_lsp_metric_20250816020746.py +0 -118
  346. neverlib/.history/metrics/lpc_me_20250816013111.py +0 -0
  347. neverlib/.history/metrics/lpc_me_20250816013129.py +0 -121
  348. neverlib/.history/metrics/lpc_me_20250816015430.py +0 -103
  349. neverlib/.history/metrics/lpc_me_20250816015535.py +0 -96
  350. neverlib/.history/metrics/lpc_me_20250816015542.py +0 -96
  351. neverlib/.history/metrics/lpc_me_20250816015636.py +0 -97
  352. neverlib/.history/metrics/lpc_me_20250816015658.py +0 -104
  353. neverlib/.history/metrics/lpc_me_20250816015703.py +0 -100
  354. neverlib/.history/metrics/lpc_me_20250816015945.py +0 -128
  355. neverlib/.history/metrics/snr_20250806010538.py +0 -177
  356. neverlib/.history/metrics/snr_20250806211634.py +0 -184
  357. neverlib/.history/metrics/snr_20250827224201.py +0 -182
  358. neverlib/.history/metrics/snr_20250827234019.py +0 -186
  359. neverlib/.history/metrics/snr_20250827234028.py +0 -186
  360. neverlib/.history/metrics/snr_20250827234030.py +0 -186
  361. neverlib/.history/metrics/spec_20250805234209.py +0 -45
  362. neverlib/.history/metrics/spec_20250816135530.py +0 -11
  363. neverlib/.history/metrics/spec_20250816135654.py +0 -16
  364. neverlib/.history/metrics/spec_20250816135736.py +0 -68
  365. neverlib/.history/metrics/spec_20250816135904.py +0 -75
  366. neverlib/.history/metrics/spec_20250816135921.py +0 -82
  367. neverlib/.history/metrics/spec_20250816140111.py +0 -82
  368. neverlib/.history/metrics/spec_20250816140543.py +0 -136
  369. neverlib/.history/metrics/spec_20250816140559.py +0 -172
  370. neverlib/.history/metrics/spec_20250816140602.py +0 -172
  371. neverlib/.history/metrics/spec_20250816140608.py +0 -172
  372. neverlib/.history/metrics/spec_20250816140654.py +0 -148
  373. neverlib/.history/metrics/spec_20250816140705.py +0 -144
  374. neverlib/.history/metrics/spec_20250816140755.py +0 -138
  375. neverlib/.history/metrics/spec_20250816140823.py +0 -170
  376. neverlib/.history/metrics/spec_20250816140832.py +0 -170
  377. neverlib/.history/metrics/spec_20250816140833.py +0 -170
  378. neverlib/.history/metrics/spec_20250816140922.py +0 -147
  379. neverlib/.history/metrics/spec_20250816141148.py +0 -107
  380. neverlib/.history/metrics/spec_20250816141219.py +0 -123
  381. neverlib/.history/metrics/spec_20250816141732.py +0 -178
  382. neverlib/.history/metrics/spec_20250816141740.py +0 -178
  383. neverlib/.history/metrics/spec_20250816142030.py +0 -178
  384. neverlib/.history/metrics/spec_20250816142107.py +0 -135
  385. neverlib/.history/metrics/spec_20250816142126.py +0 -135
  386. neverlib/.history/metrics/spec_20250816142410.py +0 -135
  387. neverlib/.history/metrics/spec_20250816142415.py +0 -136
  388. neverlib/.history/metrics/spec_metric_20250816135156.py +0 -0
  389. neverlib/.history/metrics/spec_metric_20250816135226.py +0 -5
  390. neverlib/.history/metrics/spec_metric_20250816135227.py +0 -10
  391. neverlib/.history/metrics/spec_metric_20250816135306.py +0 -15
  392. neverlib/.history/metrics/spec_metric_20250816135442.py +0 -31
  393. neverlib/.history/metrics/spec_metric_20250816135448.py +0 -31
  394. neverlib/.history/metrics/spec_metric_20250816135520.py +0 -29
  395. neverlib/.history/metrics/spec_metric_20250816135537.py +0 -63
  396. neverlib/.history/metrics/spec_metric_20250816135653.py +0 -65
  397. neverlib/.history/utils/audio_split_20250805234209.py +0 -268
  398. neverlib/.history/utils/audio_split_20250904185309.py +0 -268
  399. neverlib/.history/utils/utils_20250813165516.py +0 -330
  400. neverlib/.history/utils/utils_20250904181341.py +0 -328
  401. neverlib/.history/utils/utils_20250904185546.py +0 -352
  402. neverlib/.history/utils/utils_20250904185548.py +0 -353
  403. neverlib/.history/utils/utils_20250904185603.py +0 -353
  404. neverlib/.history/utils/utils_20250904185636.py +0 -353
  405. neverlib/.history/utils/utils_20250904185658.py +0 -358
  406. neverlib/.history/utils/utils_20250904190053.py +0 -359
  407. neverlib/.history/vad/PreProcess_20250805234211.py +0 -63
  408. neverlib/.history/vad/PreProcess_20250809232455.py +0 -63
  409. neverlib/.history/vad/PreProcess_20250816020725.py +0 -66
  410. neverlib/.history/vad/VAD_Silero_20250805234211.py +0 -50
  411. neverlib/.history/vad/VAD_Silero_20250809232456.py +0 -50
  412. neverlib/.history/vad/VAD_WebRTC_20250805234211.py +0 -61
  413. neverlib/.history/vad/VAD_WebRTC_20250809232456.py +0 -61
  414. neverlib/.history/vad/VAD_funasr_20250805234211.py +0 -54
  415. neverlib/.history/vad/VAD_funasr_20250809232456.py +0 -54
  416. neverlib/.history/vad/VAD_vadlib_20250805234211.py +0 -70
  417. neverlib/.history/vad/VAD_vadlib_20250809232455.py +0 -70
  418. neverlib/.history/vad/VAD_whisper_20250805234211.py +0 -55
  419. neverlib/.history/vad/VAD_whisper_20250809232456.py +0 -55
  420. neverlib/.specstory/.what-is-this.md +0 -69
  421. neverlib/.specstory/history/2025-08-05_17-06Z-/350/277/231/344/270/200/346/255/245/347/232/204/347/233/256/347/232/204/346/230/257/344/273/200/344/271/210.md +0 -424
  422. neverlib/.specstory/history/2025-08-22_02-10Z-/345/256/214/345/226/204/345/207/275/346/225/260/347/232/204/345/212/237/350/203/275/345/222/214/345/217/230/351/207/217/345/220/215/345/273/272/350/256/256.md +0 -247
  423. neverlib/.specstory/history/2025-08-26_11-54Z-oserror-missing-shared-object-file.md +0 -87
  424. neverlib/.specstory/history/2025-08-27_08-07Z-/345/256/214/345/226/204/346/265/213/350/257/225/346/226/207/346/241/243/347/232/204/350/256/250/350/256/272.md +0 -296
  425. neverlib/.specstory/history/2025-08-27_08-29Z-delete-python-file-command.md +0 -211
  426. neverlib/.specstory/history/2025-08-27_09-05Z-/345/234/250jupyter/344/270/255/346/222/255/346/224/276/351/237/263/351/242/221/347/232/204/344/273/243/347/240/201/344/277/256/346/224/271.md +0 -357
  427. neverlib-0.2.8.dist-info/RECORD +0 -510
  428. {neverlib-0.2.8.dist-info → neverlib-0.2.9.dist-info}/WHEEL +0 -0
  429. {neverlib-0.2.8.dist-info → neverlib-0.2.9.dist-info}/licenses/LICENSE +0 -0
  430. {neverlib-0.2.8.dist-info → neverlib-0.2.9.dist-info}/top_level.txt +0 -0
@@ -1,471 +0,0 @@
1
- # -*- coding:utf-8 -*-
2
- # Author:凌逆战 | Never
3
- # Date: 2024/9/27
4
- """
5
-
6
- """
7
- import random
8
- import numpy as np
9
- import soundfile as sf
10
- from scipy import signal
11
- from neverlib.utils import EPS
12
- from neverlib.filter import HPFilter
13
-
14
-
15
- def limiter(wav, threshold=0.999):
16
- """
17
- 简单限幅器, threshold=0.999 ~ -0.1dBFS
18
- 超过阈值的样本被压缩到阈值限制
19
- """
20
- peak = np.max(np.abs(wav))
21
- if peak > threshold:
22
- scalar = threshold / (peak + EPS)
23
- wav = wav * scalar
24
- return wav
25
-
26
-
27
- def add_reverb(wav, rir, ratio=1, mode="same"):
28
- """添加混响,
29
- Args:
30
- wav: [T, channel]
31
- rir: [T, channel]
32
- ratio: 0-1
33
- mode: "same" for SE or "full" for kws
34
- """
35
- if random.random() < ratio:
36
- wav = signal.fftconvolve(wav, rir, mode=mode) # (28671, 3)
37
- # note: 建议过完添加混响后再进行归一化, 否则可能会出现溢出
38
- # 防止削波
39
- if np.max(np.abs(wav)) > 1:
40
- scale_factor = 1 / np.max(np.abs(wav))
41
- wav *= scale_factor
42
- return wav
43
-
44
-
45
- def snr_aug_changeNoise(clean, noise, target_snr, hpf=False, sr=16000, order=4, cutoff=100):
46
- """
47
- 保持语音不变, 改变噪声的幅度
48
- HP: 高通滤波, 如果你的数据工频干扰较高, 建议设置为True, 否则snr会不准
49
- snr = 10 * log10(signal_power / k*noise_power)
50
- """
51
- assert clean.shape == noise.shape, "clean and noise must have the same shape"
52
- clean_tmp, noise_tmp = clean.copy(), noise.copy()
53
- if hpf:
54
- clean_tmp = HPFilter(clean_tmp, sr=sr, order=order, cutoff=cutoff)
55
- noise_tmp = HPFilter(noise_tmp, sr=sr, order=order, cutoff=cutoff)
56
- # 纯净语音功率, 噪声功率
57
- clean_power, noise_power = np.mean(clean_tmp ** 2), np.mean(noise_tmp ** 2)
58
- noise_scale = np.sqrt(clean_power / (noise_power * 10 ** (target_snr / 10) + EPS))
59
- noisy = clean + noise_scale * noise
60
- # 防止削波
61
- if np.max(np.abs(noisy)) > 1:
62
- scale_factor = 1 / np.max(np.abs(noisy))
63
- noisy *= scale_factor
64
- clean *= scale_factor
65
- return noisy, clean
66
-
67
-
68
- def snr_aug_changeClean(clean, noise, target_snr, clip_check=True, hpf=False, sr=16000, order=4, cutoff=100):
69
- """
70
- 保持噪声不变,改变纯净语音的幅度以达到目标信噪比
71
- snr = 10 * log10(k*signal_power/ noise_power)
72
- """
73
- assert clean.shape == noise.shape, "clean and noise must have the same shape"
74
- clean_tmp, noise_tmp = clean.copy(), noise.copy()
75
- if hpf:
76
- clean_tmp = HPFilter(clean_tmp, sr=sr, order=order, cutoff=cutoff)
77
- noise_tmp = HPFilter(noise_tmp, sr=sr, order=order, cutoff=cutoff)
78
- # 纯净语音功率, 噪声功率
79
- clean_power, noise_power = np.mean(clean_tmp ** 2), np.mean(noise_tmp ** 2)
80
- # 计算纯净信号需要的幅度因子
81
- clean_scale = np.sqrt(noise_power * 10 ** (target_snr / 10) / (clean_power + EPS))
82
- noisy = clean * clean_scale + noise
83
- # 防止削波
84
- if clip_check:
85
- if np.max(np.abs(noisy)) > 1:
86
- scale_factor = 1 / np.max(np.abs(noisy))
87
- noisy *= scale_factor
88
- clean *= (scale_factor * clean_scale)
89
- return noisy, clean
90
-
91
-
92
- def snr_diff_changeNoise(clean, noise, target_snr, hpf=False, sr=16000, order=4, cutoff=100):
93
- """
94
- 保持语音不变, 改变噪声的幅度, 和snr_aug_changeNoise作用等效
95
- snr = 10 * log10(signal_power / k*noise_power)
96
- """
97
- assert clean.shape == noise.shape, "clean and noise must have the same shape"
98
- clean_tmp, noise_tmp = clean.copy(), noise.copy()
99
- if hpf:
100
- clean_tmp = HPFilter(clean_tmp, sr=sr, order=order, cutoff=cutoff)
101
- noise_tmp = HPFilter(noise_tmp, sr=sr, order=order, cutoff=cutoff)
102
- # 纯净语音功率, 噪声功率
103
- clean_power, noise_power = np.mean(clean_tmp ** 2), np.mean(noise_tmp ** 2)
104
- source_snr = 10 * np.log10(clean_power / (noise_power + EPS) + EPS)
105
- noise_dB = source_snr - target_snr # 噪声还差多少dB
106
- noise_gain = 10 ** (noise_dB / 20)
107
- noisy = clean + noise_gain * noise
108
- # 防止削波
109
- if np.max(np.abs(noisy)) > 1:
110
- scale_factor = 1 / np.max(np.abs(noisy))
111
- noisy *= scale_factor
112
- clean *= scale_factor
113
- return noisy, clean
114
-
115
-
116
- def snr_diff_changeClean(clean, noise, target_snr, clip_check=True, hpf=False, sr=16000, order=4, cutoff=100):
117
- """
118
- 保持噪声不变, 改变纯净语音的幅度, 和snr_aug_changeClean作用等效
119
- snr = 10 * log10(signal_power / k*noise_power)
120
- """
121
- assert clean.shape == noise.shape, "clean and noise must have the same shape"
122
- clean_tmp, noise_tmp = clean.copy(), noise.copy()
123
- if hpf:
124
- clean_tmp = HPFilter(clean_tmp, sr=sr, order=order, cutoff=cutoff)
125
- noise_tmp = HPFilter(noise_tmp, sr=sr, order=order, cutoff=cutoff)
126
- # 纯净语音功率, 噪声功率
127
- clean_power, noise_power = np.mean(clean_tmp ** 2), np.mean(noise_tmp ** 2)
128
- source_snr = 10 * np.log10(clean_power / (noise_power + EPS) + EPS)
129
- clean_dB = target_snr - source_snr # 纯净语音还差多少dB
130
- clean_gain = 10 ** (clean_dB / 20)
131
- noisy = clean_gain * clean + noise
132
- # 防止削波
133
- if clip_check:
134
- if np.max(np.abs(noisy)) > 1:
135
- scale_factor = 1 / np.max(np.abs(noisy))
136
- noisy *= scale_factor
137
- clean *= (scale_factor * clean_gain)
138
- return noisy, clean
139
-
140
-
141
- def snr_aug_Interpolation(clean, noise, target_snr, hpf=False, sr=16000, order=4, cutoff=100):
142
- """
143
- 在已知clean_len<=noise_len的情况下
144
- 将clean插入到noise中的snr aug方法
145
- Args:
146
- clean: 语音
147
- noise: 噪声
148
- snr: snr=random.uniform(*snr_range)
149
- """
150
- clean_len, noise_len = clean.shape[0], noise.shape[0]
151
- assert clean_len <= noise_len, f"clean_len must be less than noise_len."
152
- clean_tmp, noise_tmp = clean.copy(), noise.copy()
153
- if hpf:
154
- clean_tmp = HPFilter(clean_tmp, sr=sr, order=order, cutoff=cutoff)
155
- noise_tmp = HPFilter(noise_tmp, sr=sr, order=order, cutoff=cutoff)
156
- noisy = noise.copy()
157
- index = random.randint(0, noise_len - clean_len)
158
- noise_tmp = noise_tmp[index:index + clean_len, :]
159
- # 这里必须把clip_check设置为False, 否则外面的noise和里面的不一致
160
- noisy_tmp, clean_tmp = snr_aug_changeClean(clean_tmp, noise_tmp, target_snr, clip_check=False, hpf=False)
161
- noisy[index:index + clean_len, :] = noisy_tmp
162
- # 防止削波
163
- if np.max(np.abs(noisy)) > 1:
164
- scale_factor = 1 / np.max(np.abs(noisy))
165
- noisy *= scale_factor
166
- clean *= scale_factor
167
- return noisy, np.pad(clean, ((index, noise_len - index - clean_len), (0, 0)))
168
-
169
-
170
- def get_snr_use_vad(wav, vad, sr=16000):
171
- # 通过vad获得语音原始的snr
172
- wav = HPFilter(wav, sr=sr, order=6, cutoff=100)
173
- vadstart, vadend = vad["start"], vad["end"]
174
- noise = np.concatenate([wav[:vadstart], wav[vadend:]], axis=0)
175
- speech_segment = wav[vadstart:vadend]
176
-
177
- # 计算信噪比
178
- # 统计语音段的均方功率谱
179
- P_speech_noise = np.mean(speech_segment ** 2) # 语音+噪声功率
180
- # P_speech_noise = np.mean(wav ** 2) # 如果用全局的, 会存在噪声功率过大的问题, 导致snr过低
181
- P_noise = np.mean(noise ** 2) # 纯噪声功率
182
-
183
- # 计算净语音功率(确保非负)
184
- P_speech = max(P_speech_noise - P_noise, 1e-8)
185
- if P_noise < 1e-8:
186
- P_noise = 1e-8
187
-
188
- snr = 10 * np.log10(P_speech / P_noise) # 计算 SNR
189
- # snr保留小数点后一位
190
- return round(snr, 1)
191
-
192
-
193
- def snr_aug_vad_Interpolation(clean, noise, target_snr, vad, hpf=False, sr=16000, order=4, cutoff=100):
194
- """
195
- 在已知clean_len<=noise_len的情况下, 将clean插入到noise中的snr aug方法,
196
- 使用VAD信息, 精确地找到语音位置
197
- Args:
198
- clean: 语音
199
- noise: 噪声
200
- vad: {"start": xxx, "end": xxx}
201
- """
202
- clean_len, noise_len = clean.shape[0], noise.shape[0]
203
- assert clean_len <= noise_len, f"clean_len must be less than noise_len."
204
- clean_tmp, noise_tmp = clean.copy(), noise.copy()
205
- noisy = noise.copy()
206
- index = random.randint(0, noise_len - clean_len)
207
- noise = noise[index:index + clean_len, :] # 现在语音和噪声长度一致
208
- if hpf:
209
- clean_tmp = HPFilter(clean_tmp, sr=sr, order=order, cutoff=cutoff)
210
- noise_tmp = HPFilter(noise_tmp, sr=sr, order=order, cutoff=cutoff)
211
- # 只根据语音段求SNR
212
- clean_vad = clean_tmp[vad["start"]:vad["end"]]
213
- noise_tmp = noise_tmp[vad["start"]:vad["end"]]
214
- power_clean, power_noise = np.mean(clean_vad ** 2), np.mean(noise_tmp ** 2)
215
- snr_in = 10 * np.log10(power_clean / (power_noise + EPS) + EPS)
216
- clean_dB = target_snr - snr_in # 语音还差多少dB
217
- # noise_dB = snr_in - target_snr # 噪声还差多少dB
218
- clean_gain = 10 ** (clean_dB / 20)
219
- noisy_tmp = clean_gain * clean + noise
220
-
221
- noisy[index:index + clean_len, :] = noisy_tmp
222
- # 防止削波
223
- if np.max(np.abs(noisy)) > 1:
224
- scale_factor = 1 / np.max(np.abs(noisy))
225
- noisy *= scale_factor
226
- clean *= (scale_factor * clean_gain)
227
- return noisy, np.pad(clean, ((index, noise_len - index - clean_len), (0, 0)))
228
-
229
-
230
- def get_audio_segments(wav_len, audio_path_list, sr=16000):
231
- """
232
- 从音频列表中随机拼接指定长度音频
233
- Args:
234
- wav_len: 需要返回的音频长度
235
- audio_path_list: 音频路径列表
236
- sr: 采样率
237
- Returns:返回指定长度的音频
238
- """
239
- audio_len = 0
240
- wav_list = []
241
- while audio_len < wav_len:
242
- audio_path = random.choice(audio_path_list)
243
- wav, wav_sr = sf.read(audio_path, always_2d=True, dtype='float32')
244
- assert wav_sr == sr, f"音频采样率是{wav_sr}, 期望{sr}"
245
- audio_len += len(wav)
246
- wav_list.append(wav)
247
- wav = np.concatenate(wav_list, axis=0)
248
- if len(wav) > wav_len:
249
- # 随机截取clean_len
250
- start = random.randint(0, len(wav) - wav_len)
251
- wav = wav[start:start + wav_len, :]
252
- return wav
253
-
254
-
255
- # ----------------------------------------------------------------
256
- # 音量增强
257
- # ----------------------------------------------------------------
258
- def volume_norm(wav):
259
- """
260
- 音量归一化
261
- :param wav: (T,)
262
- :return: (T,)
263
- """
264
- wav = wav / (np.max(np.abs(wav)) + 1e-8)
265
- return wav
266
-
267
-
268
- def volume_aug(wav, range, rate, method="linmax"):
269
- """音量增强 """
270
- if random.random() < rate:
271
- target_level = random.uniform(range[0], range[1])
272
- if method == "dbrms":
273
- wav_rms = (wav ** 2).mean() ** 0.5
274
- scalar = 10 ** (target_level / 20) / (np.max(wav_rms) + EPS)
275
- elif method == "linmax":
276
- ipt_max = np.max(np.abs(wav))
277
- scalar = target_level / (ipt_max + EPS)
278
- else:
279
- raise ValueError("method must be 'dbrms' or 'linmax'")
280
- wav *= scalar
281
- return wav
282
-
283
-
284
- def volume_aug_dbrms(wav, target_level, hpf=False, sr=16000, order=4, cutoff=100):
285
- """
286
- 音量增强, 使用dbrms方法
287
- Args:
288
- wav: 音频
289
- target_level: 目标音量, 单位dB
290
- hpf: 是否高通滤波
291
- sr: 采样率
292
- order: 滤波器阶数
293
- cutoff: 截止频率
294
- """
295
- wav_tmp = wav.copy()
296
- if hpf:
297
- wav_tmp = HPFilter(wav_tmp, sr=sr, order=order, cutoff=cutoff)
298
- wav_rms = (wav_tmp ** 2).mean() ** 0.5
299
- scalar = 10 ** (target_level / 20) / (np.max(wav_rms) + EPS)
300
- wav *= scalar
301
- wav = limiter(wav)
302
- return wav
303
-
304
-
305
- def volume_aug_linmax(wav, target_level, hpf=False, sr=16000, order=4, cutoff=100):
306
- """
307
- 音量增强, 使用linmax方法
308
- Args:
309
- wav: 音频
310
- target_level: 目标音量, 单位dB
311
- hpf: 是否高通滤波
312
- sr: 采样率
313
- order: 滤波器阶数
314
- cutoff: 截止频率
315
- """
316
- assert target_level > 0 and target_level < 1, "target_level must be between 0 and 1"
317
- wav_tmp = wav.copy()
318
- if hpf:
319
- wav_tmp = HPFilter(wav_tmp, sr=sr, order=order, cutoff=cutoff)
320
- wav_max = np.max(np.abs(wav_tmp))
321
- scalar = target_level / (wav_max + EPS)
322
- wav *= scalar
323
- wav = limiter(wav)
324
-
325
- return wav
326
-
327
-
328
- import pyloudnorm as pyln
329
-
330
- def volume_aug_lufs(wav, target_lufs, hpf=False, sr=16000, order=4, cutoff=100):
331
- """
332
- 音量增强, 使用lufs方法,
333
- LUFS是“感知响度” → 跟人耳听感对齐,而且符合国际响度标准。
334
-
335
- LUFS 使用 感知加权(K-weighting)
336
- - 高频增强(模拟人耳在 3~6kHz 的敏感)
337
- - 低频衰减(降低 <100Hz 对响度的影响)。
338
- 使用 短时块(400ms)能量 + 响度门限(-70 LUFS) 过滤极静音段。
339
-
340
- Args:
341
- wav: 音频
342
- target_lufs: 目标音量, 单位lufs
343
- hpf: 是否高通滤波
344
- sr: 采样率
345
- order: 滤波器阶数
346
- cutoff: 截止频率
347
-
348
- 补充信息:
349
- ## 推荐的 target_lufs 值(行业参考)
350
- 平台 推荐目标 LUFS
351
- YouTube / Spotify -14
352
- Apple Music -16
353
- 广播 / TV -23
354
- 游戏音频 -16 ~ -18
355
- 有声书 -18 ~ -20
356
- """
357
- wav_tmp = wav.copy()
358
- if hpf:
359
- wav_tmp = HPFilter(wav_tmp, sr=sr, order=4, cutoff=1000)
360
-
361
- # Step2: 创建 LUFS 测量器(ITU-R BS.1770)
362
- meter = pyln.Meter(sr, block_size=0.400) # block_size=400ms
363
-
364
- # Step3: 测量当前 LUFS
365
- loudness = meter.integrated_loudness(wav_tmp)
366
-
367
- # Step4: 计算增益并应用
368
- loudness_diff = target_lufs - loudness
369
- scalar = 10 ** (loudness_diff / 20.0)
370
- wav = wav * scalar
371
-
372
- wav = limiter(wav, threshold=0.999) # Step5: 限幅
373
- return wav
374
-
375
- def measure_loudness(wav, sr):
376
- """
377
- 测量音频的 Peak / RMS / LUFS,以及峰均比(Crest Factor)
378
-
379
- 参数:
380
- wav: np.ndarray, 音频波形(范围 [-1, 1])
381
- sr: int, 采样率
382
-
383
- 返回:
384
- dict:
385
- - peak_dbfs: 峰值(dBFS)
386
- - rms_dbfs: 均方根电平(dBFS)
387
- - lufs: 感知响度(LUFS,ITU-R BS.1770-4标准)
388
- - crest_factor_db: 峰均比(dB),峰值与RMS的差值
389
- """
390
- EPS = 1e-9
391
-
392
- # 1. Peak
393
- peak_linear = np.max(np.abs(wav))
394
- peak_dbfs = 20 * np.log10(peak_linear + EPS)
395
-
396
- # 2. RMS
397
- rms_val = np.sqrt(np.mean(wav ** 2))
398
- rms_dbfs = 20 * np.log10(rms_val + EPS)
399
-
400
- # 3. LUFS
401
- meter = pyln.Meter(sr, block_size=0.400) # 400ms 块
402
- loudness_lufs = meter.integrated_loudness(wav)
403
-
404
- # 4. Crest Factor (峰均比)
405
- crest_factor_db = peak_dbfs - rms_dbfs
406
-
407
- return {
408
- "peak_dbfs": peak_dbfs,
409
- "rms_dbfs": rms_dbfs,
410
- "lufs": loudness_lufs,
411
- "crest_factor_db": crest_factor_db
412
- }
413
-
414
-
415
- def volume_convert(value,
416
- from_unit="linear", to_unit="dBFS",
417
- crest_factor_db=None, lufs_offset=None):
418
- """
419
- 音量单位转换函数
420
-
421
- 参数:
422
- value: float
423
- 输入值(可能是线性幅度、dBFS、LUFS)
424
- from_unit: str
425
- 输入单位: "linear", "dBFS", "RMS_dBFS", "LUFS"
426
- to_unit: str
427
- 输出单位: "linear", "dBFS", "RMS_dBFS", "LUFS"
428
- crest_factor_db: float | None
429
- 峰均比(用于 Peak <-> RMS 的转换)
430
- lufs_offset: float | None
431
- LUFS 与 RMS 的差值(用于 RMS <-> LUFS 转换)
432
- 例如, 对人声,LUFS ≈ RMS_dBFS - 1.5
433
-
434
- 返回:
435
- float
436
- """
437
- EPS = 1e-9
438
-
439
- # Step 1: 统一转换成线性幅度(以满刻度 1.0 为基准)
440
- if from_unit == "linear":
441
- lin_val = value
442
- elif from_unit in ("dBFS", "Peak_dBFS"):
443
- lin_val = 10 ** (value / 20)
444
- elif from_unit == "RMS_dBFS":
445
- lin_val = 10 ** (value / 20)
446
- elif from_unit == "LUFS":
447
- if lufs_offset is None:
448
- raise ValueError("LUFS ↔ RMS 转换需要提供 lufs_offset")
449
- rms_dbfs = value + lufs_offset
450
- lin_val = 10 ** (rms_dbfs / 20)
451
- else:
452
- raise ValueError(f"未知单位:{from_unit}")
453
-
454
- # Step 2: 从线性幅度转换到目标单位
455
- if to_unit == "linear":
456
- return lin_val
457
- elif to_unit in ("dBFS", "Peak_dBFS"):
458
- return 20 * np.log10(lin_val + EPS)
459
- elif to_unit == "RMS_dBFS":
460
- if from_unit in ("dBFS", "Peak_dBFS") and crest_factor_db is not None:
461
- # 用Peak -> RMS
462
- peak_dbfs = 20 * np.log10(lin_val + EPS)
463
- return peak_dbfs - crest_factor_db
464
- return 20 * np.log10(lin_val + EPS)
465
- elif to_unit == "LUFS":
466
- if lufs_offset is None:
467
- raise ValueError("RMS ↔ LUFS 转换需要提供 lufs_offset")
468
- rms_dbfs = 20 * np.log10(lin_val + EPS)
469
- return rms_dbfs - lufs_offset
470
- else:
471
- raise ValueError(f"未知单位:{to_unit}")