neverlib 0.2.8__py3-none-any.whl → 0.3.0__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.
- neverlib/Docs/audio_aug/test_volume.ipynb +8 -8
- neverlib/Docs/filter/biquad.ipynb +1 -1
- neverlib/Docs/filter/filter_family.ipynb +4 -4
- neverlib/Docs/vad/VAD_WebRTC.ipynb +4 -4
- neverlib/Docs/vad/VAD_whisper.ipynb +2 -2
- neverlib/LLM/__init__.py +37 -0
- neverlib/LLM/bailian.py +342 -0
- neverlib/LLM/image.py +73 -0
- neverlib/LLM/text.py +32 -0
- neverlib/QA/ImpactNoiseRejection.py +119 -0
- neverlib/QA/gen_init.py +13 -16
- neverlib/__init__.py +5 -5
- neverlib/audio_aug/HarmonicDistortion.py +11 -11
- neverlib/audio_aug/README.md +3 -0
- neverlib/audio_aug/__init__.py +2 -2
- neverlib/audio_aug/audio_aug.py +18 -18
- neverlib/audio_aug/coder_aug.py +25 -25
- neverlib/audio_aug/coder_aug2.py +10 -10
- neverlib/audio_aug/loss_packet_aug.py +16 -16
- neverlib/audio_aug/quant_aug.py +7 -7
- neverlib/data_analyze/README.md +1 -1
- neverlib/data_analyze/__init__.py +2 -2
- neverlib/data_analyze/dataset_analyzer.py +2 -2
- neverlib/data_analyze/quality_metrics.py +12 -12
- neverlib/data_analyze/statistics.py +1 -1
- neverlib/data_analyze/visualization.py +1 -1
- neverlib/filter/README.md +3 -3
- neverlib/filter/__init__.py +2 -2
- neverlib/filter/auto_eq/README.md +2 -2
- neverlib/filter/auto_eq/__init__.py +2 -2
- neverlib/filter/auto_eq/de_eq.py +1 -1
- neverlib/filter/auto_eq/ga_eq_advanced.py +2 -2
- neverlib/filter/auto_eq/ga_eq_basic.py +1 -1
- neverlib/filter/biquad.py +1 -1
- neverlib/filter/core.py +8 -5
- neverlib/metrics/README.md +35 -0
- neverlib/metrics/__init__.py +2 -2
- neverlib/metrics/dnsmos.py +2 -2
- neverlib/metrics/lpc_lsp.py +8 -8
- neverlib/metrics/pesq_c/PESQ +0 -0
- neverlib/metrics/snr.py +5 -5
- neverlib/metrics/spec.py +23 -23
- neverlib/metrics/test_pesq.py +3 -3
- neverlib/signal_gen/babble_noise_generate.py +113 -0
- neverlib/tests/__init__.py +2 -2
- neverlib/tests/test_imports.py +1 -1
- neverlib/utils/README.md +29 -0
- neverlib/utils/__init__.py +24 -16
- neverlib/utils/audio_split.py +21 -21
- neverlib/utils/checkGPU.py +52 -79
- neverlib/utils/floder.py +115 -0
- neverlib/utils/lazy_expose.py +1 -1
- neverlib/utils/lazy_module.py +6 -6
- neverlib/utils/message.py +2 -3
- neverlib/utils/pcm.py +42 -0
- neverlib/utils/utils.py +108 -91
- neverlib/vad/README.md +5 -5
- neverlib/vad/__init__.py +2 -2
- neverlib/vad/utils.py +1 -1
- {neverlib-0.2.8.dist-info → neverlib-0.3.0.dist-info}/METADATA +17 -3
- neverlib-0.3.0.dist-info/RECORD +120 -0
- neverlib/.claude/settings.local.json +0 -9
- neverlib/.history/Docs/audio_aug/del_20250827162530.py +0 -0
- neverlib/.history/Docs/audio_aug/del_20250827162540.py +0 -2
- neverlib/.history/Docs/audio_aug/del_20250827162541.py +0 -7
- neverlib/.history/Docs/audio_aug/del_20250827162606.py +0 -7
- neverlib/.history/Docs/audio_aug/del_20250827162637.py +0 -8
- neverlib/.history/Docs/audio_aug/del_20250827162645.py +0 -8
- neverlib/.history/Docs/audio_aug/del_20250827162723.py +0 -9
- neverlib/.history/Docs/audio_aug/del_20250827162739.py +0 -9
- neverlib/.history/Docs/audio_aug/test_snr_20250806011311.py +0 -0
- neverlib/.history/Docs/audio_aug/test_snr_20250806011331.py +0 -75
- neverlib/.history/Docs/audio_aug/test_snr_20250806011342.py +0 -57
- neverlib/.history/Docs/audio_aug/test_snr_20250806011352.py +0 -57
- neverlib/.history/Docs/audio_aug/test_snr_20250806011403.py +0 -57
- neverlib/.history/Docs/audio_aug/test_snr_20250806011413.py +0 -57
- neverlib/.history/Docs/audio_aug/test_snr_20250806011435.py +0 -55
- neverlib/.history/Docs/audio_aug/test_snr_20250827161751.py +0 -55
- neverlib/.history/Docs/audio_aug/test_snr_20250827161754.py +0 -55
- neverlib/.history/Docs/audio_aug/test_snr_20250827161833.py +0 -54
- neverlib/.history/Docs/audio_aug/test_snr_20250827162017.py +0 -56
- neverlib/.history/Docs/audio_aug/test_snr_20250827162021.py +0 -57
- neverlib/.history/Docs/audio_aug/test_snr_20250827162028.py +0 -57
- neverlib/.history/Docs/audio_aug/test_snr_20250827162033.py +0 -55
- neverlib/.history/Docs/audio_aug_test/del_20250827162738.py +0 -9
- neverlib/.history/Docs/audio_aug_test/del_20250827162819.py +0 -9
- neverlib/.history/Docs/audio_aug_test/del_20250827162830.py +0 -9
- neverlib/.history/Docs/audio_aug_test/del_20250827162846.py +0 -9
- neverlib/.history/Docs/audio_aug_test/del_20250827162851.py +0 -9
- neverlib/.history/Docs/audio_aug_test/del_20250827162903.py +0 -10
- neverlib/.history/Docs/audio_aug_test/del_20250827162921.py +0 -10
- neverlib/.history/Docs/audio_aug_test/del_20250827162926.py +0 -10
- neverlib/.history/Docs/audio_aug_test/del_20250827163030.py +0 -10
- neverlib/.history/Docs/audio_aug_test/del_20250827163032.py +0 -10
- neverlib/.history/Docs/vad/1_20250810032405.py +0 -0
- neverlib/.history/Docs/vad/1_20250810032417.py +0 -39
- neverlib/.history/QA/html2markdown_20250822234112.md +0 -0
- neverlib/.history/QA/html2markdown_20250822234140.py +0 -9
- neverlib/.history/QA/html2markdown_20250822234141.md +0 -9
- neverlib/.history/QA/html2markdown_20250822234159.py +0 -12
- neverlib/.history/QA/html2markdown_20250822234200.py +0 -17
- neverlib/.history/QA/html2markdown_20250822234236.py +0 -17
- neverlib/.history/QA/html2markdown_20250822234340.py +0 -14
- neverlib/.history/QA/html2markdown_20250822234522.py +0 -18
- neverlib/.history/QA/html2markdown_20250822234601.py +0 -20
- neverlib/.history/QA/html2markdown_20250822234615.py +0 -22
- neverlib/.history/QA/html2markdown_20250822234715.py +0 -28
- neverlib/.history/QA/html2markdown_20250822234720.py +0 -27
- neverlib/.history/QA/html2markdown_20250822234903.py +0 -27
- neverlib/.history/__init___20250805234212.py +0 -41
- neverlib/.history/__init___20250904102635.py +0 -39
- neverlib/.history/__init___20250904102836.py +0 -34
- neverlib/.history/__init___20250904102838.py +0 -39
- neverlib/.history/__init___20250904102851.py +0 -33
- neverlib/.history/audio_aug/audio_aug_20250806010451.py +0 -125
- neverlib/.history/audio_aug/audio_aug_20250806010750.py +0 -138
- neverlib/.history/audio_aug/audio_aug_20250806010759.py +0 -140
- neverlib/.history/audio_aug/audio_aug_20250806010803.py +0 -140
- neverlib/.history/audio_aug/audio_aug_20250806010809.py +0 -140
- neverlib/.history/audio_aug/audio_aug_20250806011108.py +0 -140
- neverlib/.history/audio_aug/audio_aug_20250826155913.py +0 -158
- neverlib/.history/audio_aug/audio_aug_20250826164159.py +0 -159
- neverlib/.history/audio_aug/audio_aug_20250826164217.py +0 -160
- neverlib/.history/audio_aug/audio_aug_20250826164408.py +0 -161
- neverlib/.history/audio_aug/audio_aug_20250826164423.py +0 -161
- neverlib/.history/audio_aug/audio_aug_20250826164529.py +0 -161
- neverlib/.history/audio_aug/audio_aug_20250826164824.py +0 -161
- neverlib/.history/audio_aug/audio_aug_20250826164932.py +0 -162
- neverlib/.history/audio_aug/audio_aug_20250826164947.py +0 -162
- neverlib/.history/audio_aug/audio_aug_20250826165403.py +0 -162
- neverlib/.history/audio_aug/audio_aug_20250826165421.py +0 -162
- neverlib/.history/audio_aug/audio_aug_20250826165509.py +0 -163
- neverlib/.history/audio_aug/audio_aug_20250826165702.py +0 -163
- neverlib/.history/audio_aug/audio_aug_20250826165732.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826170041.py +0 -163
- neverlib/.history/audio_aug/audio_aug_20250826170105.py +0 -164
- neverlib/.history/audio_aug/audio_aug_20250826170154.py +0 -164
- neverlib/.history/audio_aug/audio_aug_20250826170220.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826170221.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826170228.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826170231.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826212001.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826220038.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826220133.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826220148.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826220154.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826220156.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826220314.py +0 -165
- neverlib/.history/audio_aug/audio_aug_20250826220343.py +0 -184
- neverlib/.history/audio_aug/audio_aug_20250826220345.py +0 -184
- neverlib/.history/audio_aug/audio_aug_20250826220349.py +0 -184
- neverlib/.history/audio_aug/audio_aug_20250826220429.py +0 -184
- neverlib/.history/audio_aug/audio_aug_20250826220447.py +0 -184
- neverlib/.history/audio_aug/audio_aug_20250826220601.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220638.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220641.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220647.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220653.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220655.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220731.py +0 -185
- neverlib/.history/audio_aug/audio_aug_20250826220739.py +0 -185
- neverlib/.history/audio_aug/audio_aug_20250826220747.py +0 -185
- neverlib/.history/audio_aug/audio_aug_20250826220801.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220822.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826220901.py +0 -186
- neverlib/.history/audio_aug/audio_aug_20250826221107.py +0 -187
- neverlib/.history/audio_aug/audio_aug_20250826221310.py +0 -188
- neverlib/.history/audio_aug/audio_aug_20250826221353.py +0 -191
- neverlib/.history/audio_aug/audio_aug_20250826221821.py +0 -191
- neverlib/.history/audio_aug/audio_aug_20250826221838.py +0 -191
- neverlib/.history/audio_aug/audio_aug_20250826221906.py +0 -191
- neverlib/.history/audio_aug/audio_aug_20250826221930.py +0 -191
- neverlib/.history/audio_aug/audio_aug_20250826221939.py +0 -191
- neverlib/.history/audio_aug/audio_aug_20250826221955.py +0 -191
- neverlib/.history/audio_aug/audio_aug_20250826222008.py +0 -197
- neverlib/.history/audio_aug/audio_aug_20250826222017.py +0 -200
- neverlib/.history/audio_aug/audio_aug_20250826222046.py +0 -203
- neverlib/.history/audio_aug/audio_aug_20250826222105.py +0 -203
- neverlib/.history/audio_aug/audio_aug_20250826222206.py +0 -203
- neverlib/.history/audio_aug/audio_aug_20250826222302.py +0 -203
- neverlib/.history/audio_aug/audio_aug_20250826222336.py +0 -203
- neverlib/.history/audio_aug/audio_aug_20250826222455.py +0 -204
- neverlib/.history/audio_aug/audio_aug_20250826222526.py +0 -204
- neverlib/.history/audio_aug/audio_aug_20250826222541.py +0 -204
- neverlib/.history/audio_aug/audio_aug_20250826222624.py +0 -202
- neverlib/.history/audio_aug/audio_aug_20250826222714.py +0 -205
- neverlib/.history/audio_aug/audio_aug_20250826222820.py +0 -205
- neverlib/.history/audio_aug/audio_aug_20250826222827.py +0 -205
- neverlib/.history/audio_aug/audio_aug_20250826222927.py +0 -232
- neverlib/.history/audio_aug/audio_aug_20250826223009.py +0 -232
- neverlib/.history/audio_aug/audio_aug_20250826223054.py +0 -232
- neverlib/.history/audio_aug/audio_aug_20250826223225.py +0 -233
- neverlib/.history/audio_aug/audio_aug_20250826223344.py +0 -236
- neverlib/.history/audio_aug/audio_aug_20250826223356.py +0 -236
- neverlib/.history/audio_aug/audio_aug_20250826223955.py +0 -242
- neverlib/.history/audio_aug/audio_aug_20250826224210.py +0 -240
- neverlib/.history/audio_aug/audio_aug_20250826224250.py +0 -242
- neverlib/.history/audio_aug/audio_aug_20250826224323.py +0 -280
- neverlib/.history/audio_aug/audio_aug_20250826224452.py +0 -263
- neverlib/.history/audio_aug/audio_aug_20250826224455.py +0 -263
- neverlib/.history/audio_aug/audio_aug_20250826224502.py +0 -263
- neverlib/.history/audio_aug/audio_aug_20250826224528.py +0 -263
- neverlib/.history/audio_aug/audio_aug_20250826224658.py +0 -263
- neverlib/.history/audio_aug/audio_aug_20250826224833.py +0 -264
- neverlib/.history/audio_aug/audio_aug_20250826225013.py +0 -269
- neverlib/.history/audio_aug/audio_aug_20250826225050.py +0 -269
- neverlib/.history/audio_aug/audio_aug_20250826225241.py +0 -268
- neverlib/.history/audio_aug/audio_aug_20250826225315.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826225404.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826225502.py +0 -265
- neverlib/.history/audio_aug/audio_aug_20250826225950.py +0 -267
- neverlib/.history/audio_aug/audio_aug_20250826225959.py +0 -268
- neverlib/.history/audio_aug/audio_aug_20250826230222.py +0 -271
- neverlib/.history/audio_aug/audio_aug_20250826230248.py +0 -270
- neverlib/.history/audio_aug/audio_aug_20250826230638.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826230755.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826230941.py +0 -265
- neverlib/.history/audio_aug/audio_aug_20250826231054.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826231117.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826231219.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826232330.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250826232352.py +0 -266
- neverlib/.history/audio_aug/audio_aug_20250827152748.py +0 -268
- neverlib/.history/audio_aug/audio_aug_20250827152806.py +0 -268
- neverlib/.history/audio_aug/audio_aug_20250827152808.py +0 -268
- neverlib/.history/audio_aug/audio_aug_20250827152917.py +0 -283
- neverlib/.history/audio_aug/audio_aug_20250827152929.py +0 -281
- neverlib/.history/audio_aug/audio_aug_20250827153100.py +0 -286
- neverlib/.history/audio_aug/audio_aug_20250827153102.py +0 -286
- neverlib/.history/audio_aug/audio_aug_20250827153301.py +0 -295
- neverlib/.history/audio_aug/audio_aug_20250827153331.py +0 -298
- neverlib/.history/audio_aug/audio_aug_20250827153525.py +0 -303
- neverlib/.history/audio_aug/audio_aug_20250827153533.py +0 -304
- neverlib/.history/audio_aug/audio_aug_20250827153541.py +0 -321
- neverlib/.history/audio_aug/audio_aug_20250827153805.py +0 -322
- neverlib/.history/audio_aug/audio_aug_20250827153832.py +0 -323
- neverlib/.history/audio_aug/audio_aug_20250827153836.py +0 -324
- neverlib/.history/audio_aug/audio_aug_20250827153846.py +0 -324
- neverlib/.history/audio_aug/audio_aug_20250827153859.py +0 -325
- neverlib/.history/audio_aug/audio_aug_20250827154453.py +0 -337
- neverlib/.history/audio_aug/audio_aug_20250827154513.py +0 -355
- neverlib/.history/audio_aug/audio_aug_20250827154538.py +0 -356
- neverlib/.history/audio_aug/audio_aug_20250827154541.py +0 -357
- neverlib/.history/audio_aug/audio_aug_20250827154612.py +0 -357
- neverlib/.history/audio_aug/audio_aug_20250827154657.py +0 -360
- neverlib/.history/audio_aug/audio_aug_20250827154708.py +0 -360
- neverlib/.history/audio_aug/audio_aug_20250827154728.py +0 -366
- neverlib/.history/audio_aug/audio_aug_20250827154755.py +0 -367
- neverlib/.history/audio_aug/audio_aug_20250827154800.py +0 -367
- neverlib/.history/audio_aug/audio_aug_20250827154917.py +0 -368
- neverlib/.history/audio_aug/audio_aug_20250827154928.py +0 -369
- neverlib/.history/audio_aug/audio_aug_20250827154932.py +0 -370
- neverlib/.history/audio_aug/audio_aug_20250827154947.py +0 -372
- neverlib/.history/audio_aug/audio_aug_20250827155015.py +0 -375
- neverlib/.history/audio_aug/audio_aug_20250827155106.py +0 -375
- neverlib/.history/audio_aug/audio_aug_20250827155114.py +0 -393
- neverlib/.history/audio_aug/audio_aug_20250827155207.py +0 -415
- neverlib/.history/audio_aug/audio_aug_20250827155300.py +0 -415
- neverlib/.history/audio_aug/audio_aug_20250827155321.py +0 -471
- neverlib/.history/audio_aug/audio_aug_20250827164703.py +0 -471
- neverlib/.history/audio_aug/audio_aug_20250827164749.py +0 -471
- neverlib/.history/audio_aug/audio_aug_20250827165252.py +0 -472
- neverlib/.history/audio_aug/audio_aug_20250827165334.py +0 -472
- neverlib/.history/audio_aug/audio_aug_20250827165404.py +0 -473
- neverlib/.history/audio_aug/audio_aug_20250827165610.py +0 -473
- neverlib/.history/audio_aug/audio_aug_20250827165805.py +0 -473
- neverlib/.history/audio_aug/audio_aug_20250827170056.py +0 -473
- neverlib/.history/audio_aug/audio_aug_20250827170106.py +0 -472
- neverlib/.history/audio_aug/audio_aug_20250827170143.py +0 -472
- neverlib/.history/audio_aug/audio_aug_20250827170216.py +0 -472
- neverlib/.history/audio_aug/audio_aug_20250827170218.py +0 -472
- neverlib/.history/audio_aug/audio_aug_20250827170314.py +0 -472
- neverlib/.history/audio_aug/audio_aug_20250827171500.py +0 -471
- neverlib/.history/audio_aug/audio_aug_20250827172347.py +0 -471
- neverlib/.history/audio_aug/audio_aug_20250827172558.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250827172559.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250827172801.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250827182522.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250827182526.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250827182626.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250827182715.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250904185444.py +0 -470
- neverlib/.history/audio_aug/audio_aug_20250904185538.py +0 -445
- neverlib/.history/dataAnalyze/__init___20250805234204.py +0 -87
- neverlib/.history/dataAnalyze/__init___20250806204125.py +0 -14
- neverlib/.history/dataAnalyze/__init___20250806204139.py +0 -14
- neverlib/.history/dataAnalyze/__init___20250806204159.py +0 -14
- neverlib/.history/data_analyze/__init___20250806204158.py +0 -14
- neverlib/.history/data_analyze/__init___20250827163248.py +0 -14
- neverlib/.history/filter/__init___20250820103351.py +0 -70
- neverlib/.history/filter/__init___20250821102348.py +0 -70
- neverlib/.history/filter/__init___20250821102405.py +0 -14
- neverlib/.history/filter/auto_eq/__init___20250819213121.py +0 -36
- neverlib/.history/filter/auto_eq/__init___20250821102241.py +0 -36
- neverlib/.history/filter/auto_eq/__init___20250821102259.py +0 -36
- neverlib/.history/filter/auto_eq/__init___20250821102307.py +0 -36
- neverlib/.history/filter/auto_eq/__init___20250821102310.py +0 -36
- neverlib/.history/filter/auto_eq/__init___20250821102318.py +0 -36
- neverlib/.history/filter/auto_eq/__init___20250821102507.py +0 -36
- neverlib/.history/filter/auto_eq/de_eq_20250820103848.py +0 -361
- neverlib/.history/filter/auto_eq/de_eq_20250821102422.py +0 -360
- neverlib/.history/filter/auto_eq/freq_eq_20250805234206.py +0 -75
- neverlib/.history/filter/auto_eq/freq_eq_20250820140732.py +0 -75
- neverlib/.history/filter/auto_eq/freq_eq_20250820140745.py +0 -75
- neverlib/.history/filter/auto_eq/freq_eq_20250820140816.py +0 -75
- neverlib/.history/filter/auto_eq/freq_eq_20250820140938.py +0 -77
- neverlib/.history/filter/auto_eq/freq_eq_20250820141003.py +0 -77
- neverlib/.history/filter/auto_eq/freq_eq_20250820141006.py +0 -77
- neverlib/.history/filter/auto_eq/freq_eq_20250820141019.py +0 -77
- neverlib/.history/filter/auto_eq/freq_eq_20250820141049.py +0 -77
- neverlib/.history/filter/auto_eq/freq_eq_20250820141211.py +0 -77
- neverlib/.history/filter/auto_eq/freq_eq_20250820141227.py +0 -77
- neverlib/.history/filter/auto_eq/freq_eq_20250820141311.py +0 -78
- neverlib/.history/filter/auto_eq/freq_eq_20250820141340.py +0 -78
- neverlib/.history/filter/auto_eq/freq_eq_20250820141712.py +0 -78
- neverlib/.history/filter/auto_eq/freq_eq_20250820141733.py +0 -78
- neverlib/.history/filter/auto_eq/freq_eq_20250820141755.py +0 -78
- neverlib/.history/filter/auto_eq/freq_eq_20250821102434.py +0 -76
- neverlib/.history/filter/auto_eq/freq_eq_20250821102500.py +0 -76
- neverlib/.history/filter/auto_eq/freq_eq_20250821102502.py +0 -76
- neverlib/.history/filter/auto_eq/freq_eq_20250821143140.py +0 -76
- neverlib/.history/filter/auto_eq/freq_eq_20250821153208.py +0 -76
- neverlib/.history/filter/auto_eq/freq_eq_20250821153214.py +0 -76
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250820102957.py +0 -380
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113054.py +0 -380
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113150.py +0 -380
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113520.py +0 -385
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250820113525.py +0 -385
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250821102212.py +0 -385
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250901110521.py +0 -385
- neverlib/.history/filter/auto_eq/ga_eq_basic_20250901110652.py +0 -385
- neverlib/.history/filter/common_20250806002134.py +0 -37
- neverlib/.history/filter/common_20250821120448.py +0 -49
- neverlib/.history/filter/common_20250821120453.py +0 -49
- neverlib/.history/metrics/dnsmos_20250806001612.py +0 -160
- neverlib/.history/metrics/dnsmos_20250815180659.py +0 -160
- neverlib/.history/metrics/dnsmos_20250815180701.py +0 -158
- neverlib/.history/metrics/dnsmos_20250815181321.py +0 -154
- neverlib/.history/metrics/dnsmos_20250815181327.py +0 -154
- neverlib/.history/metrics/dnsmos_20250815181331.py +0 -154
- neverlib/.history/metrics/dnsmos_20250815181620.py +0 -154
- neverlib/.history/metrics/dnsmos_20250815181631.py +0 -154
- neverlib/.history/metrics/dnsmos_20250815181742.py +0 -154
- neverlib/.history/metrics/dnsmos_20250815181824.py +0 -153
- neverlib/.history/metrics/dnsmos_20250815181834.py +0 -153
- neverlib/.history/metrics/dnsmos_20250815181922.py +0 -153
- neverlib/.history/metrics/dnsmos_20250815182011.py +0 -147
- neverlib/.history/metrics/dnsmos_20250815182036.py +0 -144
- neverlib/.history/metrics/dnsmos_20250815182936.py +0 -143
- neverlib/.history/metrics/dnsmos_20250815182942.py +0 -143
- neverlib/.history/metrics/dnsmos_20250815183032.py +0 -137
- neverlib/.history/metrics/dnsmos_20250815183101.py +0 -144
- neverlib/.history/metrics/dnsmos_20250815183121.py +0 -144
- neverlib/.history/metrics/dnsmos_20250815183123.py +0 -143
- neverlib/.history/metrics/dnsmos_20250815183214.py +0 -143
- neverlib/.history/metrics/dnsmos_20250815183240.py +0 -143
- neverlib/.history/metrics/dnsmos_20250815183248.py +0 -144
- neverlib/.history/metrics/dnsmos_20250815183407.py +0 -142
- neverlib/.history/metrics/dnsmos_20250815183409.py +0 -142
- neverlib/.history/metrics/dnsmos_20250815183431.py +0 -142
- neverlib/.history/metrics/dnsmos_20250815183507.py +0 -140
- neverlib/.history/metrics/dnsmos_20250815183513.py +0 -139
- neverlib/.history/metrics/dnsmos_20250815183618.py +0 -139
- neverlib/.history/metrics/dnsmos_20250815183709.py +0 -140
- neverlib/.history/metrics/dnsmos_20250815183756.py +0 -137
- neverlib/.history/metrics/dnsmos_20250815183815.py +0 -128
- neverlib/.history/metrics/dnsmos_20250815183827.py +0 -129
- neverlib/.history/metrics/dnsmos_20250815183913.py +0 -117
- neverlib/.history/metrics/dnsmos_20250815183914.py +0 -117
- neverlib/.history/metrics/dnsmos_20250815184003.py +0 -118
- neverlib/.history/metrics/dnsmos_20250815184040.py +0 -118
- neverlib/.history/metrics/dnsmos_20250815184049.py +0 -118
- neverlib/.history/metrics/dnsmos_20250815184104.py +0 -117
- neverlib/.history/metrics/dnsmos_20250815184200.py +0 -117
- neverlib/.history/metrics/lpc_lsp_metric_20250816015944.py +0 -128
- neverlib/.history/metrics/lpc_lsp_metric_20250816020142.py +0 -128
- neverlib/.history/metrics/lpc_lsp_metric_20250816020156.py +0 -128
- neverlib/.history/metrics/lpc_lsp_metric_20250816020554.py +0 -130
- neverlib/.history/metrics/lpc_lsp_metric_20250816020600.py +0 -125
- neverlib/.history/metrics/lpc_lsp_metric_20250816020631.py +0 -120
- neverlib/.history/metrics/lpc_lsp_metric_20250816020746.py +0 -118
- neverlib/.history/metrics/lpc_me_20250816013111.py +0 -0
- neverlib/.history/metrics/lpc_me_20250816013129.py +0 -121
- neverlib/.history/metrics/lpc_me_20250816015430.py +0 -103
- neverlib/.history/metrics/lpc_me_20250816015535.py +0 -96
- neverlib/.history/metrics/lpc_me_20250816015542.py +0 -96
- neverlib/.history/metrics/lpc_me_20250816015636.py +0 -97
- neverlib/.history/metrics/lpc_me_20250816015658.py +0 -104
- neverlib/.history/metrics/lpc_me_20250816015703.py +0 -100
- neverlib/.history/metrics/lpc_me_20250816015945.py +0 -128
- neverlib/.history/metrics/snr_20250806010538.py +0 -177
- neverlib/.history/metrics/snr_20250806211634.py +0 -184
- neverlib/.history/metrics/snr_20250827224201.py +0 -182
- neverlib/.history/metrics/snr_20250827234019.py +0 -186
- neverlib/.history/metrics/snr_20250827234028.py +0 -186
- neverlib/.history/metrics/snr_20250827234030.py +0 -186
- neverlib/.history/metrics/spec_20250805234209.py +0 -45
- neverlib/.history/metrics/spec_20250816135530.py +0 -11
- neverlib/.history/metrics/spec_20250816135654.py +0 -16
- neverlib/.history/metrics/spec_20250816135736.py +0 -68
- neverlib/.history/metrics/spec_20250816135904.py +0 -75
- neverlib/.history/metrics/spec_20250816135921.py +0 -82
- neverlib/.history/metrics/spec_20250816140111.py +0 -82
- neverlib/.history/metrics/spec_20250816140543.py +0 -136
- neverlib/.history/metrics/spec_20250816140559.py +0 -172
- neverlib/.history/metrics/spec_20250816140602.py +0 -172
- neverlib/.history/metrics/spec_20250816140608.py +0 -172
- neverlib/.history/metrics/spec_20250816140654.py +0 -148
- neverlib/.history/metrics/spec_20250816140705.py +0 -144
- neverlib/.history/metrics/spec_20250816140755.py +0 -138
- neverlib/.history/metrics/spec_20250816140823.py +0 -170
- neverlib/.history/metrics/spec_20250816140832.py +0 -170
- neverlib/.history/metrics/spec_20250816140833.py +0 -170
- neverlib/.history/metrics/spec_20250816140922.py +0 -147
- neverlib/.history/metrics/spec_20250816141148.py +0 -107
- neverlib/.history/metrics/spec_20250816141219.py +0 -123
- neverlib/.history/metrics/spec_20250816141732.py +0 -178
- neverlib/.history/metrics/spec_20250816141740.py +0 -178
- neverlib/.history/metrics/spec_20250816142030.py +0 -178
- neverlib/.history/metrics/spec_20250816142107.py +0 -135
- neverlib/.history/metrics/spec_20250816142126.py +0 -135
- neverlib/.history/metrics/spec_20250816142410.py +0 -135
- neverlib/.history/metrics/spec_20250816142415.py +0 -136
- neverlib/.history/metrics/spec_metric_20250816135156.py +0 -0
- neverlib/.history/metrics/spec_metric_20250816135226.py +0 -5
- neverlib/.history/metrics/spec_metric_20250816135227.py +0 -10
- neverlib/.history/metrics/spec_metric_20250816135306.py +0 -15
- neverlib/.history/metrics/spec_metric_20250816135442.py +0 -31
- neverlib/.history/metrics/spec_metric_20250816135448.py +0 -31
- neverlib/.history/metrics/spec_metric_20250816135520.py +0 -29
- neverlib/.history/metrics/spec_metric_20250816135537.py +0 -63
- neverlib/.history/metrics/spec_metric_20250816135653.py +0 -65
- neverlib/.history/utils/audio_split_20250805234209.py +0 -268
- neverlib/.history/utils/audio_split_20250904185309.py +0 -268
- neverlib/.history/utils/utils_20250813165516.py +0 -330
- neverlib/.history/utils/utils_20250904181341.py +0 -328
- neverlib/.history/utils/utils_20250904185546.py +0 -352
- neverlib/.history/utils/utils_20250904185548.py +0 -353
- neverlib/.history/utils/utils_20250904185603.py +0 -353
- neverlib/.history/utils/utils_20250904185636.py +0 -353
- neverlib/.history/utils/utils_20250904185658.py +0 -358
- neverlib/.history/utils/utils_20250904190053.py +0 -359
- neverlib/.history/vad/PreProcess_20250805234211.py +0 -63
- neverlib/.history/vad/PreProcess_20250809232455.py +0 -63
- neverlib/.history/vad/PreProcess_20250816020725.py +0 -66
- neverlib/.history/vad/VAD_Silero_20250805234211.py +0 -50
- neverlib/.history/vad/VAD_Silero_20250809232456.py +0 -50
- neverlib/.history/vad/VAD_WebRTC_20250805234211.py +0 -61
- neverlib/.history/vad/VAD_WebRTC_20250809232456.py +0 -61
- neverlib/.history/vad/VAD_funasr_20250805234211.py +0 -54
- neverlib/.history/vad/VAD_funasr_20250809232456.py +0 -54
- neverlib/.history/vad/VAD_vadlib_20250805234211.py +0 -70
- neverlib/.history/vad/VAD_vadlib_20250809232455.py +0 -70
- neverlib/.history/vad/VAD_whisper_20250805234211.py +0 -55
- neverlib/.history/vad/VAD_whisper_20250809232456.py +0 -55
- neverlib/.specstory/.what-is-this.md +0 -69
- 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
- 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
- neverlib/.specstory/history/2025-08-26_11-54Z-oserror-missing-shared-object-file.md +0 -87
- 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
- neverlib/.specstory/history/2025-08-27_08-29Z-delete-python-file-command.md +0 -211
- 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
- neverlib-0.2.8.dist-info/RECORD +0 -510
- {neverlib-0.2.8.dist-info → neverlib-0.3.0.dist-info}/WHEEL +0 -0
- {neverlib-0.2.8.dist-info → neverlib-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {neverlib-0.2.8.dist-info → neverlib-0.3.0.dist-info}/top_level.txt +0 -0
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
# -*- coding:utf-8 -*-
|
|
2
|
-
# Author: AI Assistant based on User's Demand
|
|
3
|
-
# Date: 2023-10-27 (Using Differential Evolution)
|
|
4
|
-
# Modified: 2025-01-05 (Adapted for new filters.py structure)
|
|
5
|
-
import sys
|
|
6
|
-
sys.path.append("..")
|
|
7
|
-
import numpy as np
|
|
8
|
-
import librosa
|
|
9
|
-
import soundfile as sf
|
|
10
|
-
from scipy import signal as sp_signal
|
|
11
|
-
from scipy import optimize as sp_optimize # Keep for potential 'polish' if not using internal
|
|
12
|
-
from scipy.optimize import differential_evolution # Import differential_evolution
|
|
13
|
-
import warnings
|
|
14
|
-
import matplotlib.pyplot as plt
|
|
15
|
-
import os
|
|
16
|
-
from neverlib.filter import EQFilter
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def get_filter_function(filter_type, fs):
|
|
20
|
-
"""获取滤波器函数, 返回配置好采样率的EQFilter实例的方法"""
|
|
21
|
-
eq_filter = EQFilter(fs=fs)
|
|
22
|
-
filter_func_map = {
|
|
23
|
-
'peak': eq_filter.PeakingFilter,
|
|
24
|
-
'low_shelf': eq_filter.LowshelfFilter,
|
|
25
|
-
'high_shelf': eq_filter.HighshelfFilter,
|
|
26
|
-
'low_pass': eq_filter.LowpassFilter,
|
|
27
|
-
'high_pass': eq_filter.HighpassFilter,
|
|
28
|
-
}
|
|
29
|
-
return filter_func_map.get(filter_type)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def _calculate_spectrum(audio_data, target_sr, n_fft, hop_length):
|
|
33
|
-
S = librosa.stft(audio_data, n_fft=n_fft, hop_length=hop_length, win_length=n_fft)
|
|
34
|
-
mag = np.mean(np.abs(S), axis=1)
|
|
35
|
-
epsilon = 1e-9 # IMPORTANT: Add epsilon to avoid log(0)
|
|
36
|
-
spec_db = 20 * np.log10(mag + epsilon)
|
|
37
|
-
freq_axis = librosa.fft_frequencies(sr=target_sr, n_fft=n_fft)
|
|
38
|
-
return spec_db, freq_axis
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def _load_audio_data(audio_path, target_sr):
|
|
42
|
-
data, sr_orig = sf.read(audio_path, dtype='float32')
|
|
43
|
-
if data.ndim > 1:
|
|
44
|
-
data = np.mean(data, axis=1)
|
|
45
|
-
if sr_orig != target_sr:
|
|
46
|
-
data = librosa.resample(data, orig_sr=sr_orig, target_sr=target_sr)
|
|
47
|
-
return data
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def _apply_eq_cascade(audio_data, eq_params_list, fs):
|
|
51
|
-
if not eq_params_list:
|
|
52
|
-
return audio_data
|
|
53
|
-
processed_audio = audio_data.copy()
|
|
54
|
-
|
|
55
|
-
for params in eq_params_list:
|
|
56
|
-
filter_type, fc, Q, db_gain = params['filter_type'], params['fc'], params['Q'], params.get('dBgain')
|
|
57
|
-
filter_func = get_filter_function(filter_type, fs)
|
|
58
|
-
|
|
59
|
-
if filter_func is None:
|
|
60
|
-
warnings.warn(f"Unknown filter type: {filter_type}")
|
|
61
|
-
continue
|
|
62
|
-
|
|
63
|
-
# 根据滤波器类型调用相应的方法
|
|
64
|
-
if db_gain is not None:
|
|
65
|
-
b, a = filter_func(fc=fc, Q=Q, dBgain=db_gain)
|
|
66
|
-
else:
|
|
67
|
-
b, a = filter_func(fc=fc, Q=Q)
|
|
68
|
-
|
|
69
|
-
if not np.issubdtype(processed_audio.dtype, np.floating):
|
|
70
|
-
processed_audio = processed_audio.astype(np.float32)
|
|
71
|
-
processed_audio = sp_signal.lfilter(b, a, processed_audio)
|
|
72
|
-
return processed_audio
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def _objective_function(flat_params, band_definitions, target_response_db, freq_axis, fs, n_fft):
|
|
76
|
-
current_cascade_response_db = np.zeros_like(freq_axis)
|
|
77
|
-
param_idx_counter = 0
|
|
78
|
-
|
|
79
|
-
for band_def in band_definitions:
|
|
80
|
-
band_type = band_def['type']
|
|
81
|
-
# Safety check for parameter length (can happen if bounds are wrong for DE)
|
|
82
|
-
if param_idx_counter + 1 >= len(flat_params):
|
|
83
|
-
warnings.warn(
|
|
84
|
-
f"Parameter array too short in objective function. Expected at least {param_idx_counter + 2} elements, got {len(flat_params)}")
|
|
85
|
-
return np.finfo(np.float64).max # Return large error
|
|
86
|
-
|
|
87
|
-
fc, q_val = flat_params[param_idx_counter], flat_params[param_idx_counter + 1]
|
|
88
|
-
param_idx_counter += 2
|
|
89
|
-
|
|
90
|
-
filter_func = get_filter_function(band_type, fs)
|
|
91
|
-
if filter_func is None:
|
|
92
|
-
warnings.warn(f"Unknown filter type: {band_type}")
|
|
93
|
-
return np.finfo(np.float64).max
|
|
94
|
-
|
|
95
|
-
try:
|
|
96
|
-
if band_type in ['peak', 'low_shelf', 'high_shelf']:
|
|
97
|
-
if param_idx_counter >= len(flat_params):
|
|
98
|
-
warnings.warn(f"Parameter array too short for gain parameter in objective function.")
|
|
99
|
-
return np.finfo(np.float64).max
|
|
100
|
-
db_gain = flat_params[param_idx_counter]
|
|
101
|
-
param_idx_counter += 1
|
|
102
|
-
b, a = filter_func(fc=fc, Q=q_val, dBgain=db_gain)
|
|
103
|
-
else:
|
|
104
|
-
b, a = filter_func(fc=fc, Q=q_val)
|
|
105
|
-
|
|
106
|
-
w, h = sp_signal.freqz(b, a, worN=freq_axis, fs=fs)
|
|
107
|
-
# Add epsilon to avoid log(0) which results in -inf and can break mean calculation
|
|
108
|
-
h_abs = np.abs(h)
|
|
109
|
-
h_db = 20 * np.log10(h_abs + 1e-9)
|
|
110
|
-
current_cascade_response_db += h_db
|
|
111
|
-
|
|
112
|
-
except Exception as e:
|
|
113
|
-
warnings.warn(f"Error computing filter response for {band_type}: {e}")
|
|
114
|
-
return np.finfo(np.float64).max
|
|
115
|
-
|
|
116
|
-
error = np.mean((current_cascade_response_db - target_response_db)**2)
|
|
117
|
-
if np.isnan(error) or np.isinf(error): # Handle potential nan/inf from objective
|
|
118
|
-
# This might happen if parameters lead to unstable filters or extreme responses
|
|
119
|
-
# print(f"Objective function returned NaN/Inf. Current error: {error}")
|
|
120
|
-
# print(f"Params (first few): {flat_params[:6]}")
|
|
121
|
-
return np.finfo(np.float64).max # Return a very large number
|
|
122
|
-
return error
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def _get_initial_params_and_bounds(band_definitions, fs, target_response_db, freq_axis):
|
|
126
|
-
x0, bounds_list = [], [] # Changed bounds to bounds_list
|
|
127
|
-
min_fc, max_fc = 20.0, fs / 2.0 * 0.98
|
|
128
|
-
num_gain_filters = sum(1 for bd in band_definitions if bd['type'] in ['peak', 'low_shelf', 'high_shelf'])
|
|
129
|
-
log_fcs = np.logspace(np.log10(max(min_fc, 30)), np.log10(min(max_fc, fs / 2.1)), num_gain_filters, endpoint=True) if num_gain_filters > 0 else []
|
|
130
|
-
gain_filter_idx = 0
|
|
131
|
-
for band_def in band_definitions:
|
|
132
|
-
band_type = band_def['type']
|
|
133
|
-
initial_fc = band_def.get('initial_fc')
|
|
134
|
-
if initial_fc is None:
|
|
135
|
-
if band_type in ['peak', 'low_shelf', 'high_shelf'] and gain_filter_idx < len(log_fcs):
|
|
136
|
-
initial_fc = log_fcs[gain_filter_idx]
|
|
137
|
-
elif band_type == 'low_shelf':
|
|
138
|
-
initial_fc = np.clip(80, min_fc, max_fc)
|
|
139
|
-
elif band_type == 'high_shelf':
|
|
140
|
-
initial_fc = np.clip(8000, min_fc, max_fc)
|
|
141
|
-
elif band_type == 'low_pass':
|
|
142
|
-
initial_fc = np.clip(fs / 2.2, min_fc, max_fc)
|
|
143
|
-
elif band_type == 'high_pass':
|
|
144
|
-
initial_fc = np.clip(40, min_fc, max_fc)
|
|
145
|
-
else:
|
|
146
|
-
initial_fc = (min_fc + max_fc) / 2
|
|
147
|
-
x0.append(np.clip(initial_fc, min_fc, max_fc))
|
|
148
|
-
bounds_list.append((min_fc, max_fc))
|
|
149
|
-
initial_q = band_def.get('initial_Q', 1.0 if band_type == 'peak' else 0.707)
|
|
150
|
-
x0.append(initial_q)
|
|
151
|
-
bounds_list.append((0.1, 20.0))
|
|
152
|
-
if band_type in ['peak', 'low_shelf', 'high_shelf']:
|
|
153
|
-
fc_idx = np.argmin(np.abs(freq_axis - initial_fc))
|
|
154
|
-
initial_gain_default = target_response_db[fc_idx] if len(target_response_db) > 0 and fc_idx < len(target_response_db) else 0.0
|
|
155
|
-
initial_gain = band_def.get('initial_dBgain', initial_gain_default)
|
|
156
|
-
x0.append(np.clip(initial_gain, -20.0, 20.0))
|
|
157
|
-
bounds_list.append((-30.0, 30.0))
|
|
158
|
-
gain_filter_idx += 1
|
|
159
|
-
return np.array(x0), bounds_list # Return bounds_list for differential_evolution
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
def plot_spectra_comparison(spectra_data, freq_axis, title="Spectra Comparison"):
|
|
163
|
-
plt.figure(figsize=(12, 7))
|
|
164
|
-
for label, spec_db in spectra_data.items():
|
|
165
|
-
plt.plot(freq_axis, spec_db, label=label, alpha=0.8)
|
|
166
|
-
plt.xscale('log') # Re-enabled log scale for frequency axis
|
|
167
|
-
plt.xlabel("Frequency (Hz)")
|
|
168
|
-
plt.ylabel("Magnitude (dB)")
|
|
169
|
-
plt.title(title)
|
|
170
|
-
plt.legend()
|
|
171
|
-
plt.grid(True, which="both", ls="-", alpha=0.5) # Added which="both" for log grid
|
|
172
|
-
if len(freq_axis) > 0:
|
|
173
|
-
plt.xlim([20, freq_axis[-1]])
|
|
174
|
-
valid_spectra = [s[np.isfinite(s)] for s in spectra_data.values() if s is not None and len(s[np.isfinite(s)]) > 0]
|
|
175
|
-
if valid_spectra:
|
|
176
|
-
min_y = min(np.min(s) for s in valid_spectra) - 10
|
|
177
|
-
max_y = max(np.max(s) for s in valid_spectra) + 10
|
|
178
|
-
if np.isfinite(min_y) and np.isfinite(max_y):
|
|
179
|
-
plt.ylim([min_y, max_y])
|
|
180
|
-
plt.tight_layout()
|
|
181
|
-
try:
|
|
182
|
-
clean_title = "".join(c if c.isalnum() or c in [' ', '_', '-'] else '_' for c in title) # Sanitize more robustly
|
|
183
|
-
plt.savefig(f"{clean_title.replace(' ', '_')}.png")
|
|
184
|
-
# if plt.isinteractive():
|
|
185
|
-
# plt.show()
|
|
186
|
-
plt.close()
|
|
187
|
-
except Exception as e:
|
|
188
|
-
print(f"Error saving/showing plot: {e}")
|
|
189
|
-
finally:
|
|
190
|
-
plt.close()
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def match_frequency_response(
|
|
194
|
-
source_audio_path: str,
|
|
195
|
-
target_audio_path: str,
|
|
196
|
-
output_eq_audio_path: str = "source_eq_matched.wav",
|
|
197
|
-
num_eq_bands: int = 10,
|
|
198
|
-
sampling_rate: int = 16000,
|
|
199
|
-
fft_size: int = 1024,
|
|
200
|
-
hop_length_ratio: float = 0.25,
|
|
201
|
-
eq_band_config_list: list = None,
|
|
202
|
-
optimizer_options: dict = None, # For DE, e.g., {'popsize': 20, 'maxiter': 500, 'workers': -1}
|
|
203
|
-
plot_results: bool = True,
|
|
204
|
-
verbose: bool = False
|
|
205
|
-
):
|
|
206
|
-
hop_length = int(fft_size * hop_length_ratio)
|
|
207
|
-
if verbose:
|
|
208
|
-
print(f"SR={sampling_rate}, FFT={fft_size}, Hop={hop_length}")
|
|
209
|
-
print("Spectrum smoothing is DISABLED.")
|
|
210
|
-
|
|
211
|
-
source_data = _load_audio_data(source_audio_path, sampling_rate)
|
|
212
|
-
target_data = _load_audio_data(target_audio_path, sampling_rate)
|
|
213
|
-
|
|
214
|
-
source_spec_db, freq_axis = _calculate_spectrum(source_data, sampling_rate, fft_size, hop_length)
|
|
215
|
-
target_spec_db, _ = _calculate_spectrum(target_data, sampling_rate, fft_size, hop_length)
|
|
216
|
-
|
|
217
|
-
target_eq_overall_response_db = target_spec_db - source_spec_db
|
|
218
|
-
|
|
219
|
-
# _get_initial_params_and_bounds returns x0 and a list of (min,max) tuples for bounds
|
|
220
|
-
actual_num_bands = len(eq_band_config_list)
|
|
221
|
-
_, de_bounds = _get_initial_params_and_bounds(eq_band_config_list, sampling_rate, target_eq_overall_response_db, freq_axis)
|
|
222
|
-
|
|
223
|
-
if verbose:
|
|
224
|
-
print(f"EQ bands: {len(eq_band_config_list)}, Total params: {len(de_bounds)}")
|
|
225
|
-
|
|
226
|
-
# Default options for differential_evolution
|
|
227
|
-
# Note: popsize is often set to N_params * 10 or 15.
|
|
228
|
-
# maxiter might need to be lower than for L-BFGS-B for similar runtime, or higher for better solution.
|
|
229
|
-
num_params_to_optimize = len(de_bounds)
|
|
230
|
-
default_de_options = {
|
|
231
|
-
'strategy': 'best1bin',
|
|
232
|
-
'maxiter': 200 * actual_num_bands if actual_num_bands > 0 else 200, # Max generations
|
|
233
|
-
'popsize': 15, # Population size per generation (popsize * num_params_to_optimize evaluations per generation)
|
|
234
|
-
'tol': 0.01,
|
|
235
|
-
'mutation': (0.5, 1),
|
|
236
|
-
'recombination': 0.7,
|
|
237
|
-
'disp': verbose,
|
|
238
|
-
'polish': True, # Apply a local minimizer (L-BFGS-B) at the end
|
|
239
|
-
'updating': 'deferred', # For parallel processing
|
|
240
|
-
'workers': -1 # Use all available CPU cores
|
|
241
|
-
}
|
|
242
|
-
if optimizer_options:
|
|
243
|
-
default_de_options.update(optimizer_options)
|
|
244
|
-
|
|
245
|
-
obj_args = (eq_band_config_list, target_eq_overall_response_db, freq_axis, sampling_rate, fft_size)
|
|
246
|
-
|
|
247
|
-
if verbose:
|
|
248
|
-
print(f"Starting Differential Evolution, options: {default_de_options} (Smoothing DISABLED)...")
|
|
249
|
-
|
|
250
|
-
result = differential_evolution(
|
|
251
|
-
_objective_function,
|
|
252
|
-
bounds=de_bounds, # Pass the list of (min, max) tuples
|
|
253
|
-
args=obj_args,
|
|
254
|
-
**default_de_options # Pass all other options as keyword arguments
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
if verbose:
|
|
258
|
-
print(f"DE Optimization: Success={result.success}, Msg='{result.message}', NFEV={result.nfev},nit={result.nit}, FunVal={result.fun:.4e}")
|
|
259
|
-
|
|
260
|
-
optimized_params_flat = result.x
|
|
261
|
-
# ... (Rest of the function: formatting parameters, applying EQ, plotting - remains the same) ...
|
|
262
|
-
optimized_eq_parameters_list = []
|
|
263
|
-
current_param_idx = 0
|
|
264
|
-
for i, band_def in enumerate(eq_band_config_list):
|
|
265
|
-
params = {'filter_type': band_def['type'], 'fs': float(sampling_rate)}
|
|
266
|
-
params['fc'] = float(optimized_params_flat[current_param_idx])
|
|
267
|
-
params['Q'] = float(optimized_params_flat[current_param_idx + 1])
|
|
268
|
-
current_param_idx += 2
|
|
269
|
-
if params['filter_type'] in ['peak', 'low_shelf', 'high_shelf']:
|
|
270
|
-
params['dBgain'] = float(optimized_params_flat[current_param_idx])
|
|
271
|
-
current_param_idx += 1
|
|
272
|
-
else:
|
|
273
|
-
params['dBgain'] = None
|
|
274
|
-
optimized_eq_parameters_list.append(params)
|
|
275
|
-
|
|
276
|
-
eq_audio_data = None
|
|
277
|
-
if output_eq_audio_path:
|
|
278
|
-
eq_audio_data = _apply_eq_cascade(source_data, optimized_eq_parameters_list, sampling_rate)
|
|
279
|
-
max_val = np.max(np.abs(eq_audio_data))
|
|
280
|
-
if max_val > 1.0:
|
|
281
|
-
eq_audio_data /= max_val
|
|
282
|
-
warnings.warn(f"EQ'd audio clipped (max: {max_val:.2f}), scaled.")
|
|
283
|
-
elif max_val == 0 and len(eq_audio_data) > 0:
|
|
284
|
-
warnings.warn(f"EQ'd audio is all zeros.")
|
|
285
|
-
sf.write(output_eq_audio_path, eq_audio_data, sampling_rate, subtype='FLOAT')
|
|
286
|
-
if verbose:
|
|
287
|
-
print(f"EQ'd audio saved: {output_eq_audio_path}")
|
|
288
|
-
|
|
289
|
-
if plot_results:
|
|
290
|
-
spectra_to_plot = {"Source": source_spec_db, "Target": target_spec_db}
|
|
291
|
-
plot_title_main = f"Spectra (DE) - {len(eq_band_config_list)} bands - No Smoothing"
|
|
292
|
-
eq_spec_db, _ = _calculate_spectrum(eq_audio_data, sampling_rate, fft_size, hop_length)
|
|
293
|
-
spectra_to_plot["EQ'd Source"] = eq_spec_db
|
|
294
|
-
plot_spectra_comparison(spectra_to_plot, freq_axis, title=plot_title_main)
|
|
295
|
-
return optimized_eq_parameters_list, eq_audio_data
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
# --- Example Usage ---
|
|
299
|
-
if __name__ == '__main__':
|
|
300
|
-
source_file = "../data/white.wav"
|
|
301
|
-
target_file = "../data/white_EQ.wav"
|
|
302
|
-
output_eq_file = "../data/white_EQ_matched_DE.wav"
|
|
303
|
-
|
|
304
|
-
SR = 16000
|
|
305
|
-
NFFT = 1024
|
|
306
|
-
|
|
307
|
-
custom_band_config = [
|
|
308
|
-
{'type': 'high_pass', 'initial_fc': 40, 'initial_Q': 0.7},
|
|
309
|
-
{'type': 'low_shelf', 'initial_fc': 150, 'initial_Q': 0.7},
|
|
310
|
-
{'type': 'peak', 'initial_fc': 250},
|
|
311
|
-
{'type': 'peak', 'initial_fc': 500},
|
|
312
|
-
{'type': 'peak', 'initial_fc': 750},
|
|
313
|
-
{'type': 'peak', 'initial_fc': 1000},
|
|
314
|
-
{'type': 'peak', 'initial_fc': 1500},
|
|
315
|
-
{'type': 'peak', 'initial_fc': 2500},
|
|
316
|
-
{'type': 'peak', 'initial_fc': 3500},
|
|
317
|
-
{'type': 'peak', 'initial_fc': 5000},
|
|
318
|
-
{'type': 'peak', 'initial_fc': 6500},
|
|
319
|
-
{'type': 'high_shelf', 'initial_fc': 7000, 'initial_Q': 0.7},
|
|
320
|
-
] # 12 bands
|
|
321
|
-
|
|
322
|
-
# Differential Evolution optimizer options
|
|
323
|
-
# popsize * (maxiter+1) * N_params = total evaluations (approx, due to strategy)
|
|
324
|
-
# For 12 bands, ~34 params. popsize=15*34=510 is very large.
|
|
325
|
-
# Let's try popsize = 15 (relative to num_params, so DEAP default like), or fixed like 50-100.
|
|
326
|
-
# maxiter for DE is number of generations.
|
|
327
|
-
de_opt_options = {
|
|
328
|
-
'maxiter': 300, # Number of generations. Start smaller, e.g., 100-500.
|
|
329
|
-
'popsize': 20, # Population size multiplier. popsize * N_params individuals.
|
|
330
|
-
# For ~34 params, 20*34=680 individuals per generation. This is large.
|
|
331
|
-
# Let's set popsize directly to a number like 100 for now.
|
|
332
|
-
# 'popsize': 100, # Try a fixed population size
|
|
333
|
-
'mutation': (0.5, 1.0),
|
|
334
|
-
'recombination': 0.7,
|
|
335
|
-
'workers': -1, # Use all CPU cores for parallel fitness evaluation
|
|
336
|
-
'polish': True, # Recommended: polish the best solution with L-BFGS-B
|
|
337
|
-
'disp': True # Show progress
|
|
338
|
-
}
|
|
339
|
-
# Recalculate popsize for verbose message if using multiplier:
|
|
340
|
-
# num_total_params = 0
|
|
341
|
-
# for band in custom_band_config:
|
|
342
|
-
# num_total_params +=2 # fc, Q
|
|
343
|
-
# if band['type'] in ['peak', 'low_shelf', 'high_shelf']: num_total_params +=1
|
|
344
|
-
# print(f"Total parameters to optimize: {num_total_params}")
|
|
345
|
-
# de_opt_options['popsize'] = 10 * num_total_params # Example: 10 times the number of parameters
|
|
346
|
-
|
|
347
|
-
optimized_parameters, eq_processed_audio = match_frequency_response(
|
|
348
|
-
source_audio_path=source_file, target_audio_path=target_file,
|
|
349
|
-
output_eq_audio_path=output_eq_file, eq_band_config_list=custom_band_config,
|
|
350
|
-
sampling_rate=SR, fft_size=NFFT,
|
|
351
|
-
optimizer_options=de_opt_options, # Pass DE options
|
|
352
|
-
plot_results=True, verbose=True
|
|
353
|
-
)
|
|
354
|
-
|
|
355
|
-
if optimized_parameters:
|
|
356
|
-
print("\n优化后的EQ参数 (差分进化, 未平滑):")
|
|
357
|
-
for i, params in enumerate(optimized_parameters):
|
|
358
|
-
print(f" 频段 {i + 1}: 类型={params['filter_type']}, Fc={params['fc']:.1f}, Q={params['Q']:.2f}" +
|
|
359
|
-
(f", 增益={params['dBgain']:.2f}" if params['dBgain'] is not None else ""))
|
|
360
|
-
else:
|
|
361
|
-
print("未生成EQ参数或处理中发生错误。")
|