sonusai 0.18.9__py3-none-any.whl → 0.19.6__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 +81 -91
  13. sonusai/genmetrics.py +51 -61
  14. sonusai/genmix.py +105 -115
  15. sonusai/genmixdb.py +201 -174
  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 +16 -18
  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 +20 -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 +58 -101
  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 +41 -30
  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.6.dist-info}/METADATA +20 -21
  113. sonusai-0.19.6.dist-info/RECORD +125 -0
  114. {sonusai-0.18.9.dist-info → sonusai-0.19.6.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.6.dist-info}/entry_points.txt +0 -0
sonusai/genmix.py CHANGED
@@ -17,22 +17,21 @@ 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
- from dataclasses import dataclass
32
32
 
33
- from sonusai.mixture import GenMixData
34
33
  from sonusai.mixture import GeneralizedIDs
35
- from sonusai.mixture import MixtureDatabase
34
+ from sonusai.mixture import GenMixData
36
35
 
37
36
 
38
37
  def signal_handler(_sig, _frame):
@@ -40,116 +39,100 @@ def signal_handler(_sig, _frame):
40
39
 
41
40
  from sonusai import logger
42
41
 
43
- logger.info('Canceled due to keyboard interrupt')
42
+ logger.info("Canceled due to keyboard interrupt")
44
43
  sys.exit(1)
45
44
 
46
45
 
47
46
  signal.signal(signal.SIGINT, signal_handler)
48
47
 
49
48
 
50
- @dataclass
51
- 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()
49
+ def genmix(
50
+ location: str,
51
+ mixids: GeneralizedIDs = "*",
52
+ save_target: bool = False,
53
+ compute_truth: bool = False,
54
+ compute_segsnr: bool = False,
55
+ write: bool = False,
56
+ show_progress: bool = False,
57
+ force: bool = True,
58
+ ) -> list[GenMixData]:
59
+ from functools import partial
61
60
 
62
-
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
61
+ from sonusai.mixture import MixtureDatabase
62
+ from sonusai.utils import par_track
63
+ from sonusai.utils import track
74
64
 
75
65
  mixdb = MixtureDatabase(location)
76
66
  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)
67
+ progress = track(total=len(mixids), disable=not show_progress)
68
+ results = par_track(
69
+ partial(
70
+ _genmix_kernel,
71
+ location=location,
72
+ save_target=save_target,
73
+ compute_truth=compute_truth,
74
+ compute_segsnr=compute_segsnr,
75
+ force=force,
76
+ write=write,
77
+ ),
78
+ mixids,
79
+ progress=progress,
80
+ )
83
81
  progress.close()
84
82
 
85
83
  return results
86
84
 
87
85
 
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
100
-
101
-
102
- def _genmix_kernel(m_id: int) -> GenMixData:
103
- from sonusai.mixture import write_mixture_data
86
+ def _genmix_kernel(
87
+ m_id: int,
88
+ location: str,
89
+ save_target: bool,
90
+ compute_truth: bool,
91
+ compute_segsnr: bool,
92
+ force: bool,
93
+ write: bool,
94
+ ) -> GenMixData:
95
+ from sonusai.mixture import MixtureDatabase
96
+ from sonusai.mixture import write_cached_data
104
97
  from sonusai.mixture import write_mixture_metadata
105
98
 
106
- mixdb = MP_GLOBAL.mixdb
107
- save_target = MP_GLOBAL.save_target
108
- compute_truth = MP_GLOBAL.compute_truth
109
- compute_segsnr = MP_GLOBAL.compute_segsnr
110
- force = MP_GLOBAL.force
111
- write = MP_GLOBAL.write
99
+ mixdb = MixtureDatabase(location)
112
100
 
113
101
  targets = mixdb.mixture_targets(m_id=m_id, force=force)
114
102
  noise = mixdb.mixture_noise(m_id=m_id, force=force)
115
- write_data = [('targets', targets), ('noise', noise)]
103
+ write_data = [("targets", targets), ("noise", noise)]
116
104
 
117
105
  if compute_truth:
118
106
  truth_t = mixdb.mixture_truth_t(m_id=m_id, targets=targets, noise=noise, force=force)
119
- write_data.append(('truth_t', truth_t))
107
+ write_data.append(("truth_t", truth_t))
120
108
  else:
121
109
  truth_t = None
122
110
 
123
111
  target = mixdb.mixture_target(m_id=m_id, targets=targets)
124
112
  if save_target:
125
- write_data.append(('target', target))
113
+ write_data.append(("target", target))
126
114
 
127
115
  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))
116
+ segsnr_t = mixdb.mixture_segsnr_t(m_id=m_id, targets=targets, target=target, noise=noise, force=force)
117
+ write_data.append(("segsnr_t", segsnr_t))
134
118
  else:
135
119
  segsnr_t = None
136
120
 
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))
121
+ mixture = mixdb.mixture_mixture(m_id=m_id, targets=targets, target=target, noise=noise, force=force)
122
+ write_data.append(("mixture", mixture))
143
123
 
144
124
  if write:
145
- write_mixture_data(mixdb, mixdb.mixture(m_id), write_data)
125
+ write_cached_data(mixdb.location, "mixture", mixdb.mixture(m_id).name, write_data)
146
126
  write_mixture_metadata(mixdb, mixdb.mixture(m_id))
147
127
 
148
- return GenMixData(targets=targets,
149
- noise=noise,
150
- mixture=mixture,
151
- truth_t=truth_t,
152
- segsnr_t=segsnr_t)
128
+ return GenMixData(
129
+ targets=targets,
130
+ target=target,
131
+ noise=noise,
132
+ mixture=mixture,
133
+ truth_t=truth_t,
134
+ segsnr_t=segsnr_t,
135
+ )
153
136
 
154
137
 
155
138
  def main() -> None:
@@ -167,59 +150,66 @@ def main() -> None:
167
150
  from sonusai import initial_log_messages
168
151
  from sonusai import logger
169
152
  from sonusai import update_console_handler
153
+ from sonusai.mixture import MixtureDatabase
170
154
  from sonusai.mixture import check_audio_files_exist
171
155
  from sonusai.utils import human_readable_size
172
156
  from sonusai.utils import seconds_to_hms
173
157
 
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']
158
+ verbose = args["--verbose"]
159
+ location = args["LOC"]
160
+ mixids = args["--mixid"]
161
+ save_target = args["--target"]
162
+ compute_truth = args["--truth"]
163
+ compute_segsnr = args["--segsnr"]
180
164
 
181
165
  start_time = time.monotonic()
182
166
 
183
- create_file_handler(join(location, 'genmix.log'))
167
+ create_file_handler(join(location, "genmix.log"))
184
168
  update_console_handler(verbose)
185
- initial_log_messages('genmix')
169
+ initial_log_messages("genmix")
186
170
 
187
- logger.info(f'Load mixture database from {location}')
171
+ logger.info(f"Load mixture database from {location}")
188
172
  mixdb = MixtureDatabase(location)
189
173
  mixids = mixdb.mixids_to_list(mixids)
190
174
 
191
175
  total_samples = mixdb.total_samples(mixids)
192
176
  duration = total_samples / sonusai.mixture.SAMPLE_RATE
193
177
 
194
- logger.info('')
195
- logger.info(f'Found {len(mixids):,} mixtures to process')
196
- logger.info(f'{total_samples:,} samples')
178
+ logger.info("")
179
+ logger.info(f"Found {len(mixids):,} mixtures to process")
180
+ logger.info(f"{total_samples:,} samples")
197
181
 
198
182
  check_audio_files_exist(mixdb)
199
183
 
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)}')
184
+ try:
185
+ genmix(
186
+ location=location,
187
+ mixids=mixids,
188
+ save_target=save_target,
189
+ compute_truth=compute_truth,
190
+ compute_segsnr=compute_segsnr,
191
+ write=True,
192
+ show_progress=True,
193
+ )
194
+ except Exception as e:
195
+ logger.debug(e)
196
+ raise
197
+
198
+ logger.info(f"Wrote {len(mixids)} mixtures to {location}")
199
+ logger.info("")
200
+ logger.info(f"Duration: {seconds_to_hms(seconds=duration)}")
201
+ logger.info(f"mixture: {human_readable_size(total_samples * 2, 1)}")
212
202
  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)}')
203
+ logger.info(f"truth_t: {human_readable_size(total_samples * mixdb.num_classes * 4, 1)}")
204
+ logger.info(f"target: {human_readable_size(total_samples * 2, 1)}")
205
+ logger.info(f"noise: {human_readable_size(total_samples * 2, 1)}")
216
206
  if compute_segsnr:
217
- logger.info(f'segsnr: {human_readable_size(total_samples * 4, 1)}')
207
+ logger.info(f"segsnr: {human_readable_size(total_samples * 4, 1)}")
218
208
 
219
209
  end_time = time.monotonic()
220
- logger.info(f'Completed in {seconds_to_hms(seconds=end_time - start_time)}')
221
- logger.info('')
210
+ logger.info(f"Completed in {seconds_to_hms(seconds=end_time - start_time)}")
211
+ logger.info("")
222
212
 
223
213
 
224
- if __name__ == '__main__':
214
+ if __name__ == "__main__":
225
215
  main()