sonusai 0.18.9__py3-none-any.whl → 0.19.5__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 (118) hide show
  1. sonusai/__init__.py +20 -29
  2. sonusai/aawscd_probwrite.py +18 -18
  3. sonusai/audiofe.py +93 -80
  4. sonusai/calc_metric_spenh.py +395 -321
  5. sonusai/data/genmixdb.yml +5 -11
  6. sonusai/{gentcst.py → deprecated/gentcst.py} +146 -149
  7. sonusai/{plot.py → deprecated/plot.py} +177 -131
  8. sonusai/{tplot.py → deprecated/tplot.py} +124 -102
  9. sonusai/doc/__init__.py +1 -1
  10. sonusai/doc/doc.py +112 -177
  11. sonusai/doc.py +10 -10
  12. sonusai/genft.py +93 -77
  13. sonusai/genmetrics.py +59 -46
  14. sonusai/genmix.py +116 -104
  15. sonusai/genmixdb.py +194 -153
  16. sonusai/lsdb.py +56 -66
  17. sonusai/main.py +23 -20
  18. sonusai/metrics/__init__.py +2 -0
  19. sonusai/metrics/calc_audio_stats.py +29 -24
  20. sonusai/metrics/calc_class_weights.py +7 -7
  21. sonusai/metrics/calc_optimal_thresholds.py +5 -7
  22. sonusai/metrics/calc_pcm.py +3 -3
  23. sonusai/metrics/calc_pesq.py +10 -7
  24. sonusai/metrics/calc_phase_distance.py +3 -3
  25. sonusai/metrics/calc_sa_sdr.py +10 -8
  26. sonusai/metrics/calc_segsnr_f.py +15 -17
  27. sonusai/metrics/calc_speech.py +105 -47
  28. sonusai/metrics/calc_wer.py +35 -32
  29. sonusai/metrics/calc_wsdr.py +10 -7
  30. sonusai/metrics/class_summary.py +30 -27
  31. sonusai/metrics/confusion_matrix_summary.py +25 -22
  32. sonusai/metrics/one_hot.py +91 -57
  33. sonusai/metrics/snr_summary.py +53 -46
  34. sonusai/mixture/__init__.py +19 -14
  35. sonusai/mixture/audio.py +4 -6
  36. sonusai/mixture/augmentation.py +37 -43
  37. sonusai/mixture/class_count.py +5 -14
  38. sonusai/mixture/config.py +292 -225
  39. sonusai/mixture/constants.py +41 -30
  40. sonusai/mixture/data_io.py +155 -0
  41. sonusai/mixture/datatypes.py +111 -108
  42. sonusai/mixture/db_datatypes.py +54 -70
  43. sonusai/mixture/eq_rule_is_valid.py +6 -9
  44. sonusai/mixture/feature.py +40 -38
  45. sonusai/mixture/generation.py +522 -389
  46. sonusai/mixture/helpers.py +217 -272
  47. sonusai/mixture/log_duration_and_sizes.py +16 -13
  48. sonusai/mixture/mixdb.py +669 -477
  49. sonusai/mixture/soundfile_audio.py +12 -17
  50. sonusai/mixture/sox_audio.py +91 -112
  51. sonusai/mixture/sox_augmentation.py +8 -9
  52. sonusai/mixture/spectral_mask.py +4 -6
  53. sonusai/mixture/target_class_balancing.py +41 -36
  54. sonusai/mixture/targets.py +69 -67
  55. sonusai/mixture/tokenized_shell_vars.py +23 -23
  56. sonusai/mixture/torchaudio_audio.py +14 -15
  57. sonusai/mixture/torchaudio_augmentation.py +23 -27
  58. sonusai/mixture/truth.py +48 -26
  59. sonusai/mixture/truth_functions/__init__.py +26 -0
  60. sonusai/mixture/truth_functions/crm.py +56 -38
  61. sonusai/mixture/truth_functions/datatypes.py +37 -0
  62. sonusai/mixture/truth_functions/energy.py +85 -59
  63. sonusai/mixture/truth_functions/file.py +30 -30
  64. sonusai/mixture/truth_functions/phoneme.py +14 -7
  65. sonusai/mixture/truth_functions/sed.py +71 -45
  66. sonusai/mixture/truth_functions/target.py +69 -106
  67. sonusai/mkwav.py +52 -85
  68. sonusai/onnx_predict.py +46 -43
  69. sonusai/queries/__init__.py +3 -1
  70. sonusai/queries/queries.py +100 -59
  71. sonusai/speech/__init__.py +2 -0
  72. sonusai/speech/l2arctic.py +24 -23
  73. sonusai/speech/librispeech.py +16 -17
  74. sonusai/speech/mcgill.py +22 -21
  75. sonusai/speech/textgrid.py +32 -25
  76. sonusai/speech/timit.py +45 -42
  77. sonusai/speech/vctk.py +14 -13
  78. sonusai/speech/voxceleb.py +26 -20
  79. sonusai/summarize_metric_spenh.py +11 -10
  80. sonusai/utils/__init__.py +4 -3
  81. sonusai/utils/asl_p56.py +1 -1
  82. sonusai/utils/asr.py +37 -17
  83. sonusai/utils/asr_functions/__init__.py +2 -0
  84. sonusai/utils/asr_functions/aaware_whisper.py +18 -12
  85. sonusai/utils/audio_devices.py +12 -12
  86. sonusai/utils/braced_glob.py +6 -8
  87. sonusai/utils/calculate_input_shape.py +1 -4
  88. sonusai/utils/compress.py +2 -2
  89. sonusai/utils/convert_string_to_number.py +1 -3
  90. sonusai/utils/create_timestamp.py +1 -1
  91. sonusai/utils/create_ts_name.py +2 -2
  92. sonusai/utils/dataclass_from_dict.py +1 -1
  93. sonusai/utils/docstring.py +6 -6
  94. sonusai/utils/energy_f.py +9 -7
  95. sonusai/utils/engineering_number.py +56 -54
  96. sonusai/utils/get_label_names.py +8 -10
  97. sonusai/utils/human_readable_size.py +2 -2
  98. sonusai/utils/model_utils.py +3 -5
  99. sonusai/utils/numeric_conversion.py +2 -4
  100. sonusai/utils/onnx_utils.py +43 -32
  101. sonusai/utils/parallel.py +40 -27
  102. sonusai/utils/print_mixture_details.py +25 -22
  103. sonusai/utils/ranges.py +12 -12
  104. sonusai/utils/read_predict_data.py +11 -9
  105. sonusai/utils/reshape.py +19 -26
  106. sonusai/utils/seconds_to_hms.py +1 -1
  107. sonusai/utils/stacked_complex.py +8 -16
  108. sonusai/utils/stratified_shuffle_split.py +29 -27
  109. sonusai/utils/write_audio.py +2 -2
  110. sonusai/utils/yes_or_no.py +3 -3
  111. sonusai/vars.py +14 -14
  112. {sonusai-0.18.9.dist-info → sonusai-0.19.5.dist-info}/METADATA +20 -21
  113. sonusai-0.19.5.dist-info/RECORD +125 -0
  114. {sonusai-0.18.9.dist-info → sonusai-0.19.5.dist-info}/WHEEL +1 -1
  115. sonusai/mixture/truth_functions/data.py +0 -58
  116. sonusai/utils/read_mixture_data.py +0 -14
  117. sonusai-0.18.9.dist-info/RECORD +0 -125
  118. {sonusai-0.18.9.dist-info → sonusai-0.19.5.dist-info}/entry_points.txt +0 -0
sonusai/genmix.py CHANGED
@@ -17,21 +17,22 @@ Inputs:
17
17
  MIXID A glob of mixture ID(s) to generate.
18
18
 
19
19
  Outputs the following to the mixture database directory:
20
- <id>.h5:
21
- dataset: mixture
22
- dataset: targets
23
- dataset: noise
24
- dataset: target (optional)
25
- dataset: truth_t (optional)
26
- dataset: segsnr_t (optional)
27
- <id>.txt
20
+ <id>
21
+ mixture.pkl
22
+ targets.pkl
23
+ noise.pkl
24
+ target.pkl (optional)
25
+ truth_t.pkl (optional)
26
+ segsnr_t.pkl (optional)
27
+ metadata.txt
28
28
  genmix.log
29
29
  """
30
+
30
31
  import signal
31
32
  from dataclasses import dataclass
32
33
 
33
- from sonusai.mixture import GenMixData
34
34
  from sonusai.mixture import GeneralizedIDs
35
+ from sonusai.mixture import GenMixData
35
36
  from sonusai.mixture import MixtureDatabase
36
37
 
37
38
 
@@ -40,7 +41,7 @@ def signal_handler(_sig, _frame):
40
41
 
41
42
  from sonusai import logger
42
43
 
43
- logger.info('Canceled due to keyboard interrupt')
44
+ logger.info("Canceled due to keyboard interrupt")
44
45
  sys.exit(1)
45
46
 
46
47
 
@@ -49,60 +50,70 @@ signal.signal(signal.SIGINT, signal_handler)
49
50
 
50
51
  @dataclass
51
52
  class MPGlobal:
52
- mixdb: MixtureDatabase = None
53
- save_target: bool = None
54
- compute_truth: bool = None
55
- compute_segsnr: bool = None
56
- force: bool = None
57
- write: bool = None
58
-
59
-
60
- MP_GLOBAL = MPGlobal()
61
-
53
+ mixdb: MixtureDatabase
54
+ save_target: bool
55
+ compute_truth: bool
56
+ compute_segsnr: bool
57
+ force: bool
58
+ write: bool
59
+
60
+
61
+ MP_GLOBAL: MPGlobal
62
+
63
+
64
+ def genmix(
65
+ mixdb: MixtureDatabase,
66
+ mixids: GeneralizedIDs = "*",
67
+ save_target: bool = False,
68
+ compute_truth: bool = False,
69
+ compute_segsnr: bool = False,
70
+ write: bool = False,
71
+ show_progress: bool = False,
72
+ force: bool = True,
73
+ ) -> list[GenMixData]:
74
+ from sonusai.utils import par_track
75
+ from sonusai.utils import track
62
76
 
63
- def genmix(location: str,
64
- mixids: GeneralizedIDs = None,
65
- save_target: bool = False,
66
- compute_truth: bool = False,
67
- compute_segsnr: bool = False,
68
- write: bool = False,
69
- show_progress: bool = False,
70
- force: bool = True) -> list[GenMixData]:
71
- from tqdm import tqdm
72
-
73
- from sonusai.utils import pp_tqdm_imap
74
-
75
- mixdb = MixtureDatabase(location)
76
77
  mixids = mixdb.mixids_to_list(mixids)
77
- progress = tqdm(total=len(mixids), disable=not show_progress)
78
- results = pp_tqdm_imap(_genmix_kernel,
79
- mixids,
80
- initializer=_genmix_initializer,
81
- initargs=(location, save_target, compute_truth, compute_segsnr, force, write),
82
- progress=progress)
78
+ progress = track(total=len(mixids), disable=not show_progress)
79
+ results = par_track(
80
+ _genmix_kernel,
81
+ mixids,
82
+ initializer=_genmix_initializer,
83
+ initargs=(mixdb, save_target, compute_truth, compute_segsnr, force, write),
84
+ progress=progress,
85
+ )
83
86
  progress.close()
84
87
 
85
88
  return results
86
89
 
87
90
 
88
- def _genmix_initializer(location: str,
89
- save_target: bool,
90
- compute_truth: bool,
91
- compute_segsnr: bool,
92
- force: bool,
93
- write: bool) -> None:
94
- MP_GLOBAL.mixdb = MixtureDatabase(location)
95
- MP_GLOBAL.save_target = save_target
96
- MP_GLOBAL.compute_truth = compute_truth
97
- MP_GLOBAL.compute_segsnr = compute_segsnr
98
- MP_GLOBAL.force = force
99
- MP_GLOBAL.write = write
91
+ def _genmix_initializer(
92
+ mixdb: MixtureDatabase,
93
+ save_target: bool,
94
+ compute_truth: bool,
95
+ compute_segsnr: bool,
96
+ force: bool,
97
+ write: bool,
98
+ ) -> None:
99
+ global MP_GLOBAL
100
+
101
+ MP_GLOBAL = MPGlobal(
102
+ mixdb=mixdb,
103
+ save_target=save_target,
104
+ compute_truth=compute_truth,
105
+ compute_segsnr=compute_segsnr,
106
+ force=force,
107
+ write=write,
108
+ )
100
109
 
101
110
 
102
111
  def _genmix_kernel(m_id: int) -> GenMixData:
103
- from sonusai.mixture import write_mixture_data
112
+ from sonusai.mixture import write_cached_data
104
113
  from sonusai.mixture import write_mixture_metadata
105
114
 
115
+ global MP_GLOBAL
116
+
106
117
  mixdb = MP_GLOBAL.mixdb
107
118
  save_target = MP_GLOBAL.save_target
108
119
  compute_truth = MP_GLOBAL.compute_truth
@@ -112,44 +123,39 @@ def _genmix_kernel(m_id: int) -> GenMixData:
112
123
 
113
124
  targets = mixdb.mixture_targets(m_id=m_id, force=force)
114
125
  noise = mixdb.mixture_noise(m_id=m_id, force=force)
115
- write_data = [('targets', targets), ('noise', noise)]
126
+ write_data = [("targets", targets), ("noise", noise)]
116
127
 
117
128
  if compute_truth:
118
129
  truth_t = mixdb.mixture_truth_t(m_id=m_id, targets=targets, noise=noise, force=force)
119
- write_data.append(('truth_t', truth_t))
130
+ write_data.append(("truth_t", truth_t))
120
131
  else:
121
132
  truth_t = None
122
133
 
123
134
  target = mixdb.mixture_target(m_id=m_id, targets=targets)
124
135
  if save_target:
125
- write_data.append(('target', target))
136
+ write_data.append(("target", target))
126
137
 
127
138
  if compute_segsnr:
128
- segsnr_t = mixdb.mixture_segsnr_t(m_id=m_id,
129
- targets=targets,
130
- target=target,
131
- noise=noise,
132
- force=force)
133
- write_data.append(('segsnr_t', segsnr_t))
139
+ segsnr_t = mixdb.mixture_segsnr_t(m_id=m_id, targets=targets, target=target, noise=noise, force=force)
140
+ write_data.append(("segsnr_t", segsnr_t))
134
141
  else:
135
142
  segsnr_t = None
136
143
 
137
- mixture = mixdb.mixture_mixture(m_id=m_id,
138
- targets=targets,
139
- target=target,
140
- noise=noise,
141
- force=force)
142
- write_data.append(('mixture', mixture))
144
+ mixture = mixdb.mixture_mixture(m_id=m_id, targets=targets, target=target, noise=noise, force=force)
145
+ write_data.append(("mixture", mixture))
143
146
 
144
147
  if write:
145
- write_mixture_data(mixdb, mixdb.mixture(m_id), write_data)
148
+ write_cached_data(mixdb.location, "mixture", mixdb.mixture(m_id).name, write_data)
146
149
  write_mixture_metadata(mixdb, mixdb.mixture(m_id))
147
150
 
148
- return GenMixData(targets=targets,
149
- noise=noise,
150
- mixture=mixture,
151
- truth_t=truth_t,
152
- segsnr_t=segsnr_t)
151
+ return GenMixData(
152
+ targets=targets,
153
+ target=target,
154
+ noise=noise,
155
+ mixture=mixture,
156
+ truth_t=truth_t,
157
+ segsnr_t=segsnr_t,
158
+ )
153
159
 
154
160
 
155
161
  def main() -> None:
@@ -171,55 +177,61 @@ def main() -> None:
171
177
  from sonusai.utils import human_readable_size
172
178
  from sonusai.utils import seconds_to_hms
173
179
 
174
- verbose = args['--verbose']
175
- location = args['LOC']
176
- mixids = args['--mixid']
177
- save_target = args['--target']
178
- compute_truth = args['--truth']
179
- compute_segsnr = args['--segsnr']
180
+ verbose = args["--verbose"]
181
+ location = args["LOC"]
182
+ mixids = args["--mixid"]
183
+ save_target = args["--target"]
184
+ compute_truth = args["--truth"]
185
+ compute_segsnr = args["--segsnr"]
180
186
 
181
187
  start_time = time.monotonic()
182
188
 
183
- create_file_handler(join(location, 'genmix.log'))
189
+ create_file_handler(join(location, "genmix.log"))
184
190
  update_console_handler(verbose)
185
- initial_log_messages('genmix')
191
+ initial_log_messages("genmix")
186
192
 
187
- logger.info(f'Load mixture database from {location}')
193
+ logger.info(f"Load mixture database from {location}")
188
194
  mixdb = MixtureDatabase(location)
189
195
  mixids = mixdb.mixids_to_list(mixids)
190
196
 
191
197
  total_samples = mixdb.total_samples(mixids)
192
198
  duration = total_samples / sonusai.mixture.SAMPLE_RATE
193
199
 
194
- logger.info('')
195
- logger.info(f'Found {len(mixids):,} mixtures to process')
196
- logger.info(f'{total_samples:,} samples')
200
+ logger.info("")
201
+ logger.info(f"Found {len(mixids):,} mixtures to process")
202
+ logger.info(f"{total_samples:,} samples")
197
203
 
198
204
  check_audio_files_exist(mixdb)
199
205
 
200
- genmix(location=location,
201
- mixids=mixids,
202
- save_target=save_target,
203
- compute_truth=compute_truth,
204
- compute_segsnr=compute_segsnr,
205
- write=True,
206
- show_progress=True)
207
-
208
- logger.info(f'Wrote {len(mixids)} mixtures to {location}')
209
- logger.info('')
210
- logger.info(f'Duration: {seconds_to_hms(seconds=duration)}')
211
- logger.info(f'mixture: {human_readable_size(total_samples * 2, 1)}')
206
+ try:
207
+ genmix(
208
+ mixdb=mixdb,
209
+ mixids=mixids,
210
+ save_target=save_target,
211
+ compute_truth=compute_truth,
212
+ compute_segsnr=compute_segsnr,
213
+ write=True,
214
+ show_progress=True,
215
+ )
216
+ except Exception as e:
217
+ logger.debug(e)
218
+ raise
219
+
220
+ logger.info(f"Wrote {len(mixids)} mixtures to {location}")
221
+ logger.info("")
222
+ logger.info(f"Duration: {seconds_to_hms(seconds=duration)}")
223
+ logger.info(f"mixture: {human_readable_size(total_samples * 2, 1)}")
212
224
  if compute_truth:
213
- logger.info(f'truth_t: {human_readable_size(total_samples * mixdb.num_classes * 4, 1)}')
214
- logger.info(f'target: {human_readable_size(total_samples * 2, 1)}')
215
- logger.info(f'noise: {human_readable_size(total_samples * 2, 1)}')
225
+ logger.info(f"truth_t: {human_readable_size(total_samples * mixdb.num_classes * 4, 1)}")
226
+ logger.info(f"target: {human_readable_size(total_samples * 2, 1)}")
227
+ logger.info(f"noise: {human_readable_size(total_samples * 2, 1)}")
216
228
  if compute_segsnr:
217
- logger.info(f'segsnr: {human_readable_size(total_samples * 4, 1)}')
229
+ logger.info(f"segsnr: {human_readable_size(total_samples * 4, 1)}")
218
230
 
219
231
  end_time = time.monotonic()
220
- logger.info(f'Completed in {seconds_to_hms(seconds=end_time - start_time)}')
221
- logger.info('')
232
+ logger.info(f"Completed in {seconds_to_hms(seconds=end_time - start_time)}")
233
+ logger.info("")
222
234
 
223
235
 
224
- if __name__ == '__main__':
236
+ if __name__ == "__main__":
225
237
  main()