sonusai 0.18.6__py3-none-any.whl → 0.18.8__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.
sonusai/utils/__init__.py CHANGED
@@ -9,6 +9,8 @@ from .audio_devices import get_input_devices
9
9
  from .braced_glob import braced_glob
10
10
  from .braced_glob import braced_iglob
11
11
  from .calculate_input_shape import calculate_input_shape
12
+ from .compress import power_compress
13
+ from .compress import power_uncompress
12
14
  from .convert_string_to_number import convert_string_to_number
13
15
  from .create_timestamp import create_timestamp
14
16
  from .create_ts_name import create_ts_name
@@ -0,0 +1,25 @@
1
+ from sonusai.mixture import AudioF
2
+
3
+
4
+ def power_compress(feature: AudioF) -> AudioF:
5
+ import numpy as np
6
+
7
+ mag = np.abs(feature)
8
+ phase = np.angle(feature)
9
+ mag = mag ** 0.3
10
+ real_compress = mag * np.cos(phase)
11
+ imag_compress = mag * np.sin(phase)
12
+
13
+ return real_compress + 1j * imag_compress
14
+
15
+
16
+ def power_uncompress(feature: AudioF) -> AudioF:
17
+ import numpy as np
18
+
19
+ mag = np.abs(feature)
20
+ phase = np.angle(feature)
21
+ mag = mag ** (1. / 0.3)
22
+ real_uncompress = mag * np.cos(phase)
23
+ imag_uncompress = mag * np.sin(phase)
24
+
25
+ return real_uncompress + 1j * imag_uncompress
sonusai/utils/energy_f.py CHANGED
@@ -1,5 +1,4 @@
1
- from pyaaware import ForwardTransform
2
-
1
+ from sonusai import ForwardTransform
3
2
  from sonusai.mixture import AudioF
4
3
  from sonusai.mixture import AudioT
5
4
  from sonusai.mixture import EnergyF
@@ -19,7 +18,7 @@ def compute_energy_f(frequency_domain: AudioF = None,
19
18
  :return: Frequency domain per-bin energy data [frames, bins]
20
19
  """
21
20
  import numpy as np
22
-
21
+ import torch
23
22
  from sonusai import SonusAIError
24
23
 
25
24
  if frequency_domain is None:
@@ -28,7 +27,7 @@ def compute_energy_f(frequency_domain: AudioF = None,
28
27
  if transform is None:
29
28
  raise SonusAIError('Must provide ForwardTransform object')
30
29
 
31
- frequency_domain, _ = transform.execute_all(time_domain)
30
+ frequency_domain = transform.execute_all(torch.from_numpy(time_domain))[0].numpy()
32
31
 
33
32
  frames, bins = frequency_domain.shape
34
33
  result = np.empty((frames, bins), dtype=np.float32)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sonusai
3
- Version: 0.18.6
3
+ Version: 0.18.8
4
4
  Summary: Framework for building deep neural network models for sound, speech, and voice AI
5
5
  Home-page: https://aaware.com
6
6
  License: GPL-3.0-only
@@ -1,4 +1,4 @@
1
- sonusai/__init__.py,sha256=s77La_fCT4TJtXR8fT0jHrWgGwOQI5qonyS3LStzsyw,2980
1
+ sonusai/__init__.py,sha256=PakKXwYWgB0TZysZ6t9l6s33WobyS55qTR5jceMrADQ,3062
2
2
  sonusai/aawscd_probwrite.py,sha256=GukR5owp_0A3DrqSl9fHWULYgclNft4D5OkHIwfxxkc,3698
3
3
  sonusai/audiofe.py,sha256=3LssRiL73DH8teihD9f3nCvfZ0a65WQtXCqWGnKHuJM,11157
4
4
  sonusai/calc_metric_spenh.py,sha256=ee2xrx6L1lFyWSoQSiq56He3RQ1cF7T_ak-6TjejXsc,47738
@@ -10,14 +10,14 @@ sonusai/doc/__init__.py,sha256=rP5Hgn0Iys_xkuv4caxngdqehuU4zLZsiKuv8Nde67M,19
10
10
  sonusai/doc/doc.py,sha256=8gftMlCaVa0hIA_BjSHbEYgSTq_BAZwC5Ipk-BFgGp8,22919
11
11
  sonusai/doc.py,sha256=l8CaFgLI8mqx4tn0aXfxKqa2dy9GgC0zjYxZAkpmi1E,878
12
12
  sonusai/genft.py,sha256=OzET3iTE-QhrUckzidfZvCDXZlAxIF5Xe5NEf856Vvk,5662
13
- sonusai/genmetrics.py,sha256=YS5ZuhOR77-wGH8ju7z_ihQSDhYhV_iJWlWWMemLIGU,4998
13
+ sonusai/genmetrics.py,sha256=dyonwsztn23-iPPg_5FOzai-n6veuThsvrdt6iBycTE,5007
14
14
  sonusai/genmix.py,sha256=TU5aTebGHsbfwsRbynYbegGBelSma9khuQkDk0dFE3I,7075
15
15
  sonusai/genmixdb.py,sha256=gF2qas1tH9MHEFLoEMrN3kYVm-vhAKaOuZ8ev-w4MQM,19553
16
16
  sonusai/gentcst.py,sha256=W1ZO3xs7CoZkFcvOTH-FLJOIA4I7Wzb0HVRC3hGGSaM,20223
17
17
  sonusai/lsdb.py,sha256=oLyGoq46hkravDUXhI-wwhKdX_GESoOD5-E7nEJl7rc,5996
18
18
  sonusai/main.py,sha256=GC-pQrSqx9tWwIcmEo6V9SraEv5KskBLS_W_wz-f2ZM,2509
19
- sonusai/metrics/__init__.py,sha256=GEenHTytN-_qMAF7UJypqkArudJsHyctGSKd0bKUniQ,807
20
- sonusai/metrics/calc_audio_stats.py,sha256=u-HIyrqJUCb0G7WR865TcpTVkT2lsCnb2rwB67IgzEc,1308
19
+ sonusai/metrics/__init__.py,sha256=uLRKJNPxrSYtLL5zhPyr8mGGVdterS_Pi9kYDru1GHA,858
20
+ sonusai/metrics/calc_audio_stats.py,sha256=R_s-j4GA_QuFBMjR-tZn3v7QkRiIPE0QlkmczCyt2aw,1553
21
21
  sonusai/metrics/calc_class_weights.py,sha256=dyY7daEIf5Ms5tfTf6wF0fkx_GnMADHOZR_rtsfGoVM,3933
22
22
  sonusai/metrics/calc_optimal_thresholds.py,sha256=9fRfwl-aKAbzHJyqGHv4o8BpZXG9HHB7zUJObHXfYM4,3522
23
23
  sonusai/metrics/calc_pcm.py,sha256=n_QoDwdM09HZx0zMbCkJR07e9fCLo03Ilpi1nqdizRg,1906
@@ -25,30 +25,30 @@ sonusai/metrics/calc_pesq.py,sha256=vO3HnQfyzYLy6VILhP5E-Yi6HkI6T9ob_CEfPo6NG50,
25
25
  sonusai/metrics/calc_phase_distance.py,sha256=Oh7UrH4ekm48pIhOnAOmkSr1OWueq2GUlwJheoAQmnk,1905
26
26
  sonusai/metrics/calc_sa_sdr.py,sha256=pup1uzHbSqV3JprYCXmu_hbWILqRME5KAnFJGe4WXCY,2566
27
27
  sonusai/metrics/calc_sample_weights.py,sha256=0O2EH1-FKlCa0HFgKPUF1BJiknR1hCH7zLbXnoXH7Ag,945
28
- sonusai/metrics/calc_snr_f.py,sha256=cLRUYeyRuoDtXWOgrgSzFP3EMOBlRaBcPM1BcxpEU_M,1199
29
- sonusai/metrics/calc_speech.py,sha256=i-BjYiSY-M3YSbKFUOW4m7m4frkF4ikyJgyizhDjGm0,14448
28
+ sonusai/metrics/calc_segsnr_f.py,sha256=9-fFrQ2Ilcayab8bJw_nBqyF4Q15Nqyef_EFihxaMRs,3125
29
+ sonusai/metrics/calc_speech.py,sha256=r0KKY-wlNN9mEkIRUhh1hap73A4rw4G9QzSOChXQorc,14437
30
30
  sonusai/metrics/calc_wer.py,sha256=7VVW_YsbeysKOZOTtvXVAvWi8lb0PZtu-Xg2HiXomWc,2483
31
31
  sonusai/metrics/calc_wsdr.py,sha256=9wiCJsGgRGHzBpHv0zSxorMsN_JZNBPyge280Hd1W0w,2531
32
32
  sonusai/metrics/class_summary.py,sha256=4Mb25nuk6eqotnQSFMuOQL3zofGcpNXDfDlPa513ZLQ,3286
33
33
  sonusai/metrics/confusion_matrix_summary.py,sha256=3qg6TMKjJeHtNjj2YnNjPFSlMrQXt0Zcu1dLkGB_aPU,4001
34
34
  sonusai/metrics/one_hot.py,sha256=QSeH_GdqBpOAKLrNnQ8gjcPC-vSdUqC0yPEQueTA6VI,13548
35
35
  sonusai/metrics/snr_summary.py,sha256=P4U5_Xr7v9F8kF-rZBnpsVNt3p42rIVS6zmch8yfVfg,5575
36
- sonusai/mixture/__init__.py,sha256=5M8wEFLkySuaFUKFLhXGPs9SNt2fLwsr6QqEYi7-eDY,5358
36
+ sonusai/mixture/__init__.py,sha256=uX0NT0EWLYK0rR2jgZiMR0VQ7wM6lV6FU2RLzWn485w,5466
37
37
  sonusai/mixture/audio.py,sha256=2u7nnKdKwXRA6YWVwCurst5D6CQinKZj5jlm9LhXe9c,2445
38
38
  sonusai/mixture/augmentation.py,sha256=Blb90tdTwBOj5w9tRcYyS5H67YJuFiXsGqwZWd7ON4g,10468
39
39
  sonusai/mixture/class_count.py,sha256=_wFnVl2yEOnbor7pLg7cYOUeX6nioov-03Cv3SEbh2k,996
40
40
  sonusai/mixture/config.py,sha256=Fu6-HkenI_h7BdOTuGX9B-vsbLJD5pvTPd_LAncZgI4,22828
41
41
  sonusai/mixture/constants.py,sha256=90qaRIEcmIoS3Od5h_UP0_SkkvG2aE_eYPv6WsIktC0,1427
42
- sonusai/mixture/datatypes.py,sha256=uYNToIngMB4m0pgmaAFj7H27FvrMCiwaAAXDXkvIB6w,9100
42
+ sonusai/mixture/datatypes.py,sha256=2vegllgZcmFLq5NjqS7Lo97dOpOJOAj0Eml4ggP_tGo,10966
43
43
  sonusai/mixture/db_datatypes.py,sha256=GDYbcSrlgUJsesiUUNnR4s5aBkMgviiNSQDaBcgYX7I,1428
44
44
  sonusai/mixture/eq_rule_is_valid.py,sha256=MpQwRA5M76wSiQWEI1lW2cLFdPaMttBLcQp3tWD8efM,1243
45
- sonusai/mixture/feature.py,sha256=Rwuf82IoXzhHPGbKYVGcatImF_ssBf_FfvbqghVPXtg,4116
45
+ sonusai/mixture/feature.py,sha256=bHAPRaYGyS-ZTOb-RLCwDau7n1NDKsVEW30Gd9SRZYo,3676
46
46
  sonusai/mixture/generation.py,sha256=W3n6ipI-dxg4Wj6YBJn8RTpFqkAyIXzxwObeFbSLq08,42801
47
- sonusai/mixture/helpers.py,sha256=eC9ZysEa-83VLKen_9PKWzr8w9dkHj4lp6rMB2fNLbg,24759
47
+ sonusai/mixture/helpers.py,sha256=9x7gezEqPm5xKGAbwCqDMjedVEmoDWyFR_5-T_5nlno,24740
48
48
  sonusai/mixture/log_duration_and_sizes.py,sha256=baTUpqyM15wA125jo9E3posmVJUe3WlpksyO6v9Jul0,1347
49
- sonusai/mixture/mixdb.py,sha256=WPXuziS0SePtKkd7qtkE7Db8rV-TKQoUBvs4GPieTek,57332
49
+ sonusai/mixture/mixdb.py,sha256=mr9Ck4p_mCfvz1PXoUgjWcw9F-Rlw3uGiDizUvPqo2A,64359
50
50
  sonusai/mixture/soundfile_audio.py,sha256=BwO4lftNvrhoPTJERONcrpxSpM2fjO6kL_e5Ylz742A,4220
51
- sonusai/mixture/sox_audio.py,sha256=Pu5RLE8lKKlGOzZsbfcVzbDvy7YPGBuGpbD_PxowFqA,12511
51
+ sonusai/mixture/sox_audio.py,sha256=DbHuyLtEuQYtKsIRxx6g1webW_LsdgLz52P5VO37MqI,17119
52
52
  sonusai/mixture/sox_augmentation.py,sha256=kBWPrsFk0EBi71nLcKt5v0GA34bY7g9D9x0cEamNWbU,4564
53
53
  sonusai/mixture/spectral_mask.py,sha256=8AkCwhy-PSdP1Uri9miKZP-bXFYnFcH_c9xZCGrHavU,2071
54
54
  sonusai/mixture/target_class_balancing.py,sha256=NTNiKZH0_PWLooeow0l41CjJKK8ZTMVbUqz9ZkaNtWk,4900
@@ -59,16 +59,15 @@ sonusai/mixture/torchaudio_augmentation.py,sha256=1vEDHI0caL1vrgoY2lAWe4CiHE2jKR
59
59
  sonusai/mixture/truth.py,sha256=Y41pZ52Xkols9LUler0NlgnilUOscBIucmw4GcxXNzU,1612
60
60
  sonusai/mixture/truth_functions/__init__.py,sha256=82lKYHhLy8KW3gHngrocoqwupGVLVsWdIXdYs3vhjOc,359
61
61
  sonusai/mixture/truth_functions/crm.py,sha256=_Vy8UMrOUQXsrM3nutvUMWCpvI8GePr01QFlyqLFd4k,2626
62
- sonusai/mixture/truth_functions/data.py,sha256=okFJeOf43NxfdLqWFCBA2pOGqujRlNDYdAcwwR_m8z8,2875
63
- sonusai/mixture/truth_functions/energy.py,sha256=xWxjrHM1xPitRFML-X7ruqXMmXVII5MKDjU38WO6bG0,4863
62
+ sonusai/mixture/truth_functions/data.py,sha256=UcjldGSTQIQ5hq38zVKHx7X6GMmXcsChU2lyvQb8vpI,2752
63
+ sonusai/mixture/truth_functions/energy.py,sha256=BSdD1sHFs4bDnB09d5k21yb-2qECF4PScIAejKrq5uU,4907
64
64
  sonusai/mixture/truth_functions/file.py,sha256=jOJuC_3y9BH6GGOp9eKcbVrHLVRzUA80BJq59LhcBUM,1539
65
65
  sonusai/mixture/truth_functions/phoneme.py,sha256=stYdlPuNytQK_LLT61OJLfYSqKd-sDjQZdtJKGzt5wA,479
66
- sonusai/mixture/truth_functions/sed.py,sha256=8cHjEFjZaH_0hIOHhPmj4AJz2GpEADM6Ys2x4NoiWSY,2469
67
- sonusai/mixture/truth_functions/target.py,sha256=gy2OGAV_uIrZunNBRC6kZx3qg48TSzNI_HaXGzPKg3s,5763
66
+ sonusai/mixture/truth_functions/sed.py,sha256=ak6_GAdw2VxG2svHvKWHLvkL5nCDon0rD2osJbzkU3E,2512
67
+ sonusai/mixture/truth_functions/target.py,sha256=XypzXVMi24Ys13TiEM9JFY_cvHK61Lop7AB-UL5AObw,5731
68
68
  sonusai/mkwav.py,sha256=zfSyIiQTIK3KV9Ij33jkLhhZIMVYqaROcRQ4S7c4sIo,5364
69
69
  sonusai/onnx_predict.py,sha256=jSxhD2oFyGSTHOGCXbW4fRT-k4SqKOboK2JaDO-yWcs,8737
70
70
  sonusai/plot.py,sha256=ERkmxMM3qjcCDm4LGDQY4fRAncCYAzP7uW8iZ7_brcg,17105
71
- sonusai/post_spenh_targetf.py,sha256=pHaJZtms7aj4r6sgqQnEGVi6Gg8H_V29szigogV1vZ8,5002
72
71
  sonusai/queries/__init__.py,sha256=oKY5JeqZ4Cz7DwCwPc1_ydB8bUs6KaMcWFp_w02TjOs,255
73
72
  sonusai/queries/queries.py,sha256=oV-m9uiLZOwYTK-Wo7Gf8dpGisaoGf6uDsAJAarVqZI,7553
74
73
  sonusai/speech/__init__.py,sha256=SuPcU_K9wQISsZRIzsRNLtEC6cb616l-Jlx3PU-HWMs,113
@@ -82,7 +81,7 @@ sonusai/speech/vctk.py,sha256=EAMEBAzjZUI6dw15n-yI2oCN-H4tzM9t4aUVlOxpAbo,1540
82
81
  sonusai/speech/voxceleb.py,sha256=aJGN0yDb2LFLmCKmRzmUEjpZWQ-QGWw6XWOpy9967AI,2686
83
82
  sonusai/summarize_metric_spenh.py,sha256=OiZe_bhCq5esXNhsOkHDD7g4ssYrpENDHvDVoPzV9iw,1822
84
83
  sonusai/tplot.py,sha256=85T6OPZfxVegHBiSuilFpdgCNMEE0VKAuciNy4rCY5Y,14544
85
- sonusai/utils/__init__.py,sha256=UEM7SkO_xxu0VW-u_zI3e8Xih2CX4aqYjqr61LO5EQA,2271
84
+ sonusai/utils/__init__.py,sha256=ivPBOtc6m5xnHC1BKVUNxcXOxwaPc-u3jgS4jLKoGio,2347
86
85
  sonusai/utils/asl_p56.py,sha256=-bvQpd-jRQVURbkZJpRoyEAq6gTv9Rc3oFDbh5_lcjY,3861
87
86
  sonusai/utils/asr.py,sha256=V0-cW56KS6aOSakSVwQIbhkqEkKf5l8T11b8ciNxWDw,2132
88
87
  sonusai/utils/asr_functions/__init__.py,sha256=JyHK67s97bw7QzrlkboWhws4yNytdPatqzLJxfwx-yw,43
@@ -90,13 +89,14 @@ sonusai/utils/asr_functions/aaware_whisper.py,sha256=NPqc62wKhshYecu368Yvl2xcImp
90
89
  sonusai/utils/audio_devices.py,sha256=LgaXTln1oRArBzaet3rZiIO2plgtaThuGBc3sJ_sLlo,1414
91
90
  sonusai/utils/braced_glob.py,sha256=Z_XIpPK17QiP1JbzAnUC5w3oyG8ZovoyM22Wh-Q_vWU,1675
92
91
  sonusai/utils/calculate_input_shape.py,sha256=63ILxibYKuTQozY83QN8Y2OOhBEbW_1X47Q0askcHDM,984
92
+ sonusai/utils/compress.py,sha256=NSiYXSnA2WifFYbq7ZSv0wX1YKwcPNwAkrWc4-9rbDM,606
93
93
  sonusai/utils/convert_string_to_number.py,sha256=i17yIxurp8Iz6NPE-imTRlARrXWqadwm8qbOTuzHZvE,236
94
94
  sonusai/utils/create_timestamp.py,sha256=TxoQXWZ3SFdBEHLOv-ujeIsTEJuiFnKOGRy-FQq45YU,148
95
95
  sonusai/utils/create_ts_name.py,sha256=8RLKmgXwuGcbDMGgtTuc0MvGFfA7IOVqfjkE2T18GOo,405
96
96
  sonusai/utils/dataclass_from_dict.py,sha256=vAGnuMjhy0W9bxZ5usrH7mbQsFog3n0__IC4xyJyVUc,390
97
97
  sonusai/utils/db.py,sha256=lI77MJJLs4CTYxhjFUvBom2Kk2imAP34okOeO4irbDc,371
98
98
  sonusai/utils/docstring.py,sha256=JBecAq_a7KSzZ04tan0BlFA9SzhOQqY9A7Ue85kFQdU,1446
99
- sonusai/utils/energy_f.py,sha256=AsoGo3TCMnj9Kzqb9HUAYOL6vPGUseu1p-8z4LG-QYo,1462
99
+ sonusai/utils/energy_f.py,sha256=EALYk5C7vpvh8v417lneM1t4gZTfVyIlPVcF9e6-m_U,1502
100
100
  sonusai/utils/engineering_number.py,sha256=6lWRg-XW3FEllh-Zui1WHYcDnsBEY9cqcwcXPIs2-6o,5515
101
101
  sonusai/utils/get_frames_per_batch.py,sha256=xnq4tV7MT74N0H6b5ZsiAezqdXucboCLQw1Np9XpZbs,134
102
102
  sonusai/utils/get_label_names.py,sha256=bfFV_iFbXdtDp70zAz_CQQN9-QxBw_kt8vyAcr3TITM,828
@@ -119,7 +119,7 @@ sonusai/utils/stratified_shuffle_split.py,sha256=rJNXvBp-GxoKzH3OpL7k0ANSu5xMP2z
119
119
  sonusai/utils/write_audio.py,sha256=ZsPGExwM86QHLLN2LOWekK2uAqf5pV_1oRW811p0QAI,840
120
120
  sonusai/utils/yes_or_no.py,sha256=eMLXBVH0cEahiXY4W2KNORmwNQ-ba10eRtldh0y4NYg,263
121
121
  sonusai/vars.py,sha256=m2AefF0m5bXWGXpJj8Pi42zWL2ydeEj7bkak3GrtMyM,940
122
- sonusai-0.18.6.dist-info/METADATA,sha256=L4wl__zTyqiH1SEMDPIIJcgLM7Uxqa6lQ9EMXVjXRlI,2591
123
- sonusai-0.18.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
124
- sonusai-0.18.6.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
125
- sonusai-0.18.6.dist-info/RECORD,,
122
+ sonusai-0.18.8.dist-info/METADATA,sha256=KqBUJv7yMq-3lDPNfezRqi_z28ZB0w0mDEXJfBtlVmA,2591
123
+ sonusai-0.18.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
124
+ sonusai-0.18.8.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
125
+ sonusai-0.18.8.dist-info/RECORD,,
@@ -1,34 +0,0 @@
1
- import numpy as np
2
-
3
- from sonusai.mixture.datatypes import Segsnr
4
- from sonusai.mixture.datatypes import SnrFMetrics
5
-
6
-
7
- def calc_snr_f(segsnr_f: Segsnr) -> SnrFMetrics:
8
- """Calculate metrics of snr_f truth data.
9
-
10
- For now, includes mean and variance of the raw values (usually energy)
11
- and mean and standard deviation of the dB values (10 * log10).
12
- """
13
- if np.count_nonzero(segsnr_f) == 0:
14
- # If all entries are zeros
15
- return SnrFMetrics(0, 0, -np.inf, 0)
16
-
17
- tmp = np.ma.array(segsnr_f, mask=np.logical_not(np.isfinite(segsnr_f)), dtype=np.float32)
18
- if np.ma.count_masked(tmp) == np.ma.size(tmp, axis=0):
19
- # If all entries are infinite
20
- return SnrFMetrics(np.inf, 0, np.inf, 0)
21
-
22
- snr_mean = np.mean(tmp, axis=0)
23
- snr_var = np.var(tmp, axis=0)
24
-
25
- tmp = 10 * np.ma.log10(tmp)
26
- if np.ma.count_masked(tmp) == np.ma.size(tmp, axis=0):
27
- # If all entries are masked, special case where all inputs are either 0 or infinite
28
- snr_db_mean = -np.inf
29
- snr_db_std = np.inf
30
- else:
31
- snr_db_mean = np.mean(tmp, axis=0)
32
- snr_db_std = np.std(tmp, axis=0)
33
-
34
- return SnrFMetrics(snr_mean, snr_var, snr_db_mean, snr_db_std)
@@ -1,160 +0,0 @@
1
- """sonusai post_spenh_targetf
2
-
3
- usage: post_spenh_targetf [-hv] (-m MODEL) (-w KMODEL) INPUT ...
4
-
5
- options:
6
- -h, --help
7
- -v, --verbose Be verbose.
8
- -m MODEL, --model MODEL Python model file.
9
- -w KMODEL, --weights KMODEL Keras model weights file.
10
-
11
- Run post-processing on speech enhancement targetf prediction data.
12
-
13
- Inputs:
14
- MODEL A SonusAI Python model file with build and/or hypermodel functions.
15
- KMODEL A Keras model weights file (or model file with weights).
16
- INPUT A single H5 file or a glob of H5 files
17
-
18
- Outputs the following to post_spenh_targetf-<TIMESTAMP> directory:
19
- <name>.wav
20
- post_spenh_targetf.log
21
-
22
- """
23
- import signal
24
- from dataclasses import dataclass
25
-
26
-
27
- def signal_handler(_sig, _frame):
28
- import sys
29
-
30
- from sonusai import logger
31
-
32
- logger.info('Canceled due to keyboard interrupt')
33
- sys.exit(1)
34
-
35
-
36
- signal.signal(signal.SIGINT, signal_handler)
37
-
38
-
39
- @dataclass
40
- class MPGlobal:
41
- N: int = None
42
- R: int = None
43
- bin_start: int = None
44
- bin_end: int = None
45
- ttype: str = None
46
- output_dir: str = None
47
-
48
-
49
- MP_GLOBAL = MPGlobal()
50
-
51
-
52
- def main() -> None:
53
- from docopt import docopt
54
-
55
- import sonusai
56
- from sonusai.utils import trim_docstring
57
-
58
- args = docopt(trim_docstring(__doc__), version=sonusai.__version__, options_first=True)
59
-
60
- verbose = args['--verbose']
61
- model_name = args['--model']
62
- weights_name = args['--weights']
63
- input_name = args['INPUT']
64
-
65
- import time
66
- from os import makedirs
67
- from os.path import isfile
68
- from os.path import join
69
- from os.path import splitext
70
-
71
- from pyaaware import FeatureGenerator
72
- from tqdm import tqdm
73
-
74
- from sonusai import create_file_handler
75
- from sonusai import initial_log_messages
76
- from sonusai import logger
77
- from sonusai import update_console_handler
78
- from sonusai.utils import create_ts_name
79
- from sonusai.utils import import_and_check_keras_model
80
- from sonusai.utils import pp_tqdm_imap
81
- from sonusai.utils import seconds_to_hms
82
-
83
- start_time = time.monotonic()
84
-
85
- output_dir = create_ts_name('post_spenh_targetf')
86
- makedirs(output_dir, exist_ok=True)
87
-
88
- # Setup logging file
89
- create_file_handler(join(output_dir, 'post_spenh_targetf.log'))
90
- update_console_handler(verbose)
91
- initial_log_messages('post_spenh_targetf')
92
-
93
- hypermodel = import_and_check_keras_model(model_name=model_name, weights_name=weights_name)
94
-
95
- fg = FeatureGenerator(feature_mode=hypermodel.feature,
96
- num_classes=hypermodel.num_classes,
97
- truth_mutex=hypermodel.truth_mutex)
98
-
99
- MP_GLOBAL.N = fg.itransform_N
100
- MP_GLOBAL.R = fg.itransform_R
101
- MP_GLOBAL.bin_start = fg.bin_start
102
- MP_GLOBAL.bin_end = fg.bin_end
103
- MP_GLOBAL.ttype = fg.itransform_ttype
104
- MP_GLOBAL.output_dir = output_dir
105
-
106
- if not all(isfile(file) and splitext(file)[1] == '.h5' for file in input_name):
107
- logger.exception(f'Do not know how to process input from {input_name}')
108
- raise SystemExit(1)
109
-
110
- logger.info('')
111
- logger.info(f'Found {len(input_name):,} files to process')
112
-
113
- progress = tqdm(total=len(input_name))
114
- pp_tqdm_imap(_process, input_name, progress=progress)
115
- progress.close()
116
-
117
- logger.info(f'Wrote {len(input_name)} mixtures to {output_dir}')
118
- logger.info('')
119
-
120
- end_time = time.monotonic()
121
- logger.info(f'Completed in {seconds_to_hms(seconds=end_time - start_time)}')
122
- logger.info('')
123
-
124
-
125
- def _process(file: str) -> None:
126
- """Run extraction on predict data to generate estimation audio
127
- """
128
- from os.path import basename
129
- from os.path import join
130
- from os.path import splitext
131
-
132
- import h5py
133
- import numpy as np
134
- from pyaaware import AawareInverseTransform
135
-
136
- from sonusai import SonusAIError
137
- from sonusai.mixture import get_audio_from_transform
138
- from sonusai.utils import float_to_int16
139
- from sonusai.utils import unstack_complex
140
- from sonusai.utils import write_audio
141
-
142
- try:
143
- with h5py.File(file, 'r') as f:
144
- predict = unstack_complex(np.array(f['predict']))
145
- except Exception as e:
146
- raise SonusAIError(f'Error reading {file}: {e}')
147
-
148
- output_name = join(MP_GLOBAL.output_dir, splitext(basename(file))[0] + '.wav')
149
- audio, _ = get_audio_from_transform(data=predict,
150
- transform=AawareInverseTransform(N=MP_GLOBAL.N,
151
- R=MP_GLOBAL.R,
152
- bin_start=MP_GLOBAL.bin_start,
153
- bin_end=MP_GLOBAL.bin_end,
154
- ttype=MP_GLOBAL.ttype,
155
- gain=np.float32(1)))
156
- write_audio(name=output_name, audio=float_to_int16(audio))
157
-
158
-
159
- if __name__ == '__main__':
160
- main()