sonusai 0.20.3__py3-none-any.whl → 1.0.2__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 (97) hide show
  1. sonusai/__init__.py +16 -3
  2. sonusai/audiofe.py +241 -77
  3. sonusai/calc_metric_spenh.py +71 -73
  4. sonusai/config/__init__.py +3 -0
  5. sonusai/config/config.py +61 -0
  6. sonusai/config/config.yml +20 -0
  7. sonusai/config/constants.py +8 -0
  8. sonusai/constants.py +11 -0
  9. sonusai/data/genmixdb.yml +21 -36
  10. sonusai/{mixture/datatypes.py → datatypes.py} +91 -130
  11. sonusai/deprecated/plot.py +4 -5
  12. sonusai/doc/doc.py +4 -4
  13. sonusai/doc.py +11 -4
  14. sonusai/genft.py +43 -45
  15. sonusai/genmetrics.py +25 -19
  16. sonusai/genmix.py +54 -82
  17. sonusai/genmixdb.py +88 -264
  18. sonusai/ir_metric.py +30 -34
  19. sonusai/lsdb.py +41 -48
  20. sonusai/main.py +15 -22
  21. sonusai/metrics/calc_audio_stats.py +4 -293
  22. sonusai/metrics/calc_class_weights.py +4 -4
  23. sonusai/metrics/calc_optimal_thresholds.py +8 -5
  24. sonusai/metrics/calc_pesq.py +2 -2
  25. sonusai/metrics/calc_segsnr_f.py +4 -4
  26. sonusai/metrics/calc_speech.py +25 -13
  27. sonusai/metrics/class_summary.py +7 -7
  28. sonusai/metrics/confusion_matrix_summary.py +5 -5
  29. sonusai/metrics/one_hot.py +4 -4
  30. sonusai/metrics/snr_summary.py +7 -7
  31. sonusai/metrics_summary.py +38 -45
  32. sonusai/mixture/__init__.py +4 -104
  33. sonusai/mixture/audio.py +10 -39
  34. sonusai/mixture/class_balancing.py +103 -0
  35. sonusai/mixture/config.py +251 -271
  36. sonusai/mixture/constants.py +35 -39
  37. sonusai/mixture/data_io.py +25 -36
  38. sonusai/mixture/db_datatypes.py +58 -22
  39. sonusai/mixture/effects.py +386 -0
  40. sonusai/mixture/feature.py +7 -11
  41. sonusai/mixture/generation.py +478 -628
  42. sonusai/mixture/helpers.py +82 -184
  43. sonusai/mixture/ir_delay.py +3 -4
  44. sonusai/mixture/ir_effects.py +77 -0
  45. sonusai/mixture/log_duration_and_sizes.py +6 -12
  46. sonusai/mixture/mixdb.py +910 -729
  47. sonusai/mixture/pad_audio.py +35 -0
  48. sonusai/mixture/resample.py +7 -0
  49. sonusai/mixture/sox_effects.py +195 -0
  50. sonusai/mixture/sox_help.py +650 -0
  51. sonusai/mixture/spectral_mask.py +2 -2
  52. sonusai/mixture/truth.py +17 -15
  53. sonusai/mixture/truth_functions/crm.py +12 -12
  54. sonusai/mixture/truth_functions/energy.py +22 -22
  55. sonusai/mixture/truth_functions/file.py +5 -5
  56. sonusai/mixture/truth_functions/metadata.py +4 -4
  57. sonusai/mixture/truth_functions/metrics.py +4 -4
  58. sonusai/mixture/truth_functions/phoneme.py +3 -3
  59. sonusai/mixture/truth_functions/sed.py +11 -13
  60. sonusai/mixture/truth_functions/target.py +10 -10
  61. sonusai/mkwav.py +26 -29
  62. sonusai/onnx_predict.py +240 -88
  63. sonusai/queries/__init__.py +2 -2
  64. sonusai/queries/queries.py +38 -34
  65. sonusai/speech/librispeech.py +1 -1
  66. sonusai/speech/mcgill.py +1 -1
  67. sonusai/speech/timit.py +2 -2
  68. sonusai/summarize_metric_spenh.py +10 -17
  69. sonusai/utils/__init__.py +7 -1
  70. sonusai/utils/asl_p56.py +2 -2
  71. sonusai/utils/asr.py +2 -2
  72. sonusai/utils/asr_functions/aaware_whisper.py +4 -5
  73. sonusai/utils/choice.py +31 -0
  74. sonusai/utils/compress.py +1 -1
  75. sonusai/utils/dataclass_from_dict.py +19 -1
  76. sonusai/utils/energy_f.py +3 -3
  77. sonusai/utils/evaluate_random_rule.py +15 -0
  78. sonusai/utils/keyboard_interrupt.py +12 -0
  79. sonusai/utils/onnx_utils.py +3 -17
  80. sonusai/utils/print_mixture_details.py +21 -19
  81. sonusai/utils/{temp_seed.py → rand.py} +3 -3
  82. sonusai/utils/read_predict_data.py +2 -2
  83. sonusai/utils/reshape.py +3 -3
  84. sonusai/utils/stratified_shuffle_split.py +3 -3
  85. sonusai/{mixture → utils}/tokenized_shell_vars.py +1 -1
  86. sonusai/utils/write_audio.py +2 -2
  87. sonusai/vars.py +11 -4
  88. {sonusai-0.20.3.dist-info → sonusai-1.0.2.dist-info}/METADATA +4 -2
  89. sonusai-1.0.2.dist-info/RECORD +138 -0
  90. sonusai/mixture/augmentation.py +0 -444
  91. sonusai/mixture/class_count.py +0 -15
  92. sonusai/mixture/eq_rule_is_valid.py +0 -45
  93. sonusai/mixture/target_class_balancing.py +0 -107
  94. sonusai/mixture/targets.py +0 -175
  95. sonusai-0.20.3.dist-info/RECORD +0 -128
  96. {sonusai-0.20.3.dist-info → sonusai-1.0.2.dist-info}/WHEEL +0 -0
  97. {sonusai-0.20.3.dist-info → sonusai-1.0.2.dist-info}/entry_points.txt +0 -0
sonusai/genmix.py CHANGED
@@ -1,17 +1,16 @@
1
1
  """sonusai genmix
2
2
 
3
- usage: genmix [-hvgtsn] [-i MIXID] LOC
3
+ usage: genmix [-hvtsn] [-i MIXID] LOC
4
4
 
5
5
  options:
6
6
  -h, --help
7
7
  -v, --verbose Be verbose.
8
8
  -i MIXID, --mixid MIXID Mixture ID(s) to generate. [default: *].
9
- -g, --target Save target. [default: False].
10
9
  -t, --truth Save truth_t. [default: False].
11
10
  -s, --segsnr Save segsnr_t. [default: False].
12
11
  -n, --nopar Do not run in parallel. [default: False].
13
12
 
14
- Generate SonusAI mixture data from a SonusAI mixture database.
13
+ Create mixture data from a SonusAI mixture database.
15
14
 
16
15
  Inputs:
17
16
  LOC A SonusAI mixture database directory.
@@ -19,41 +18,26 @@ Inputs:
19
18
 
20
19
  Outputs the following to the mixture database directory:
21
20
  <id>
22
- mixture.pkl
23
- targets.pkl
21
+ metadata.txt
22
+ sources.pkl
23
+ source.pkl
24
24
  noise.pkl
25
- target.pkl (optional)
25
+ mixture.pkl
26
26
  truth_t.pkl (optional)
27
27
  segsnr_t.pkl (optional)
28
- metadata.txt
29
28
  genmix.log
30
29
  """
31
30
 
32
- import signal
33
-
34
- from sonusai.mixture import GeneralizedIDs
35
- from sonusai.mixture import GenMixData
36
-
37
-
38
- def signal_handler(_sig, _frame):
39
- import sys
40
-
41
- from sonusai import logger
42
-
43
- logger.info("Canceled due to keyboard interrupt")
44
- sys.exit(1)
45
-
46
-
47
- signal.signal(signal.SIGINT, signal_handler)
31
+ from sonusai.datatypes import GeneralizedIDs
32
+ from sonusai.datatypes import GenMixData
48
33
 
49
34
 
50
35
  def genmix(
51
36
  location: str,
52
37
  mixids: GeneralizedIDs = "*",
53
- save_target: bool = False,
54
38
  compute_truth: bool = False,
55
39
  compute_segsnr: bool = False,
56
- write: bool = False,
40
+ cache: bool = False,
57
41
  show_progress: bool = False,
58
42
  force: bool = True,
59
43
  no_par: bool = False,
@@ -71,11 +55,10 @@ def genmix(
71
55
  partial(
72
56
  _genmix_kernel,
73
57
  location=location,
74
- save_target=save_target,
75
58
  compute_truth=compute_truth,
76
59
  compute_segsnr=compute_segsnr,
60
+ cache=cache,
77
61
  force=force,
78
- write=write,
79
62
  ),
80
63
  mixids,
81
64
  progress=progress,
@@ -89,56 +72,43 @@ def genmix(
89
72
  def _genmix_kernel(
90
73
  m_id: int,
91
74
  location: str,
92
- save_target: bool,
93
75
  compute_truth: bool,
94
76
  compute_segsnr: bool,
77
+ cache: bool,
95
78
  force: bool,
96
- write: bool,
97
79
  ) -> GenMixData:
98
80
  from sonusai.mixture import MixtureDatabase
99
- from sonusai.mixture import write_cached_data
100
81
  from sonusai.mixture import write_mixture_metadata
101
82
 
102
83
  mixdb = MixtureDatabase(location)
103
84
 
104
85
  result = GenMixData()
105
-
106
- targets = mixdb.mixture_targets(m_id=m_id, force=force)
107
- result.targets = targets
108
- noise = mixdb.mixture_noise(m_id=m_id, force=force)
109
- result.noise = noise
110
- if write:
111
- write_cached_data(
112
- mixdb.location,
113
- "mixture",
114
- mixdb.mixture(m_id).name,
115
- [
116
- ("targets", targets),
117
- ("noise", noise),
118
- ],
119
- )
86
+ result.sources = mixdb.mixture_sources(m_id=m_id, force=force, cache=cache)
87
+ result.source = mixdb.mixture_source(m_id=m_id, sources=result.sources, force=force, cache=cache)
88
+ result.noise = mixdb.mixture_noise(m_id=m_id, sources=result.sources, force=force, cache=cache)
89
+ result.mixture = mixdb.mixture_mixture(
90
+ m_id=m_id,
91
+ sources=result.sources,
92
+ source=result.source,
93
+ noise=result.noise,
94
+ force=force,
95
+ cache=cache,
96
+ )
120
97
 
121
98
  if compute_truth:
122
- truth_t = mixdb.mixture_truth_t(m_id=m_id, targets=targets, noise=noise, force=force)
123
- result.truth_t = truth_t
124
- if write:
125
- write_cached_data(mixdb.location, "mixture", mixdb.mixture(m_id).name, [("truth_t", truth_t)])
126
-
127
- target = mixdb.mixture_target(m_id=m_id, targets=targets)
128
- result.target = target
129
- if save_target and write:
130
- write_cached_data(mixdb.location, "mixture", mixdb.mixture(m_id).name, [("target", target)])
99
+ result.truth_t = mixdb.mixture_truth_t(m_id=m_id, force=force, cache=cache)
131
100
 
132
101
  if compute_segsnr:
133
- segsnr_t = mixdb.mixture_segsnr_t(m_id=m_id, targets=targets, target=target, noise=noise, force=force)
134
- result.segsnr_t = segsnr_t
135
- if write:
136
- write_cached_data(mixdb.location, "mixture", mixdb.mixture(m_id).name, [("segsnr_t", segsnr_t)])
137
-
138
- mixture = mixdb.mixture_mixture(m_id=m_id, targets=targets, target=target, noise=noise, force=force)
139
- result.mixture = mixture
140
- if write:
141
- write_cached_data(mixdb.location, "mixture", mixdb.mixture(m_id).name, [("mixture", mixture)])
102
+ result.segsnr_t = mixdb.mixture_segsnr_t(
103
+ m_id=m_id,
104
+ sources=result.sources,
105
+ source=result.source,
106
+ noise=result.noise,
107
+ force=force,
108
+ cache=cache,
109
+ )
110
+
111
+ if cache:
142
112
  write_mixture_metadata(mixdb, m_id=m_id)
143
113
 
144
114
  return result
@@ -147,10 +117,10 @@ def _genmix_kernel(
147
117
  def main() -> None:
148
118
  from docopt import docopt
149
119
 
150
- import sonusai
120
+ from sonusai import __version__ as sai_version
151
121
  from sonusai.utils import trim_docstring
152
122
 
153
- args = docopt(trim_docstring(__doc__), version=sonusai.__version__, options_first=True)
123
+ args = docopt(trim_docstring(__doc__), version=sai_version, options_first=True)
154
124
 
155
125
  import time
156
126
  from os.path import join
@@ -159,7 +129,7 @@ def main() -> None:
159
129
  from sonusai import initial_log_messages
160
130
  from sonusai import logger
161
131
  from sonusai import update_console_handler
162
- from sonusai.mixture import SAMPLE_RATE
132
+ from sonusai.constants import SAMPLE_RATE
163
133
  from sonusai.mixture import MixtureDatabase
164
134
  from sonusai.mixture import check_audio_files_exist
165
135
  from sonusai.utils import human_readable_size
@@ -168,7 +138,6 @@ def main() -> None:
168
138
  verbose = args["--verbose"]
169
139
  location = args["LOC"]
170
140
  mixids = args["--mixid"]
171
- save_target = args["--target"]
172
141
  compute_truth = args["--truth"]
173
142
  compute_segsnr = args["--segsnr"]
174
143
  no_par = args["--nopar"]
@@ -192,20 +161,16 @@ def main() -> None:
192
161
 
193
162
  check_audio_files_exist(mixdb)
194
163
 
195
- try:
196
- genmix(
197
- location=location,
198
- mixids=mixids,
199
- save_target=save_target,
200
- compute_truth=compute_truth,
201
- compute_segsnr=compute_segsnr,
202
- write=True,
203
- show_progress=True,
204
- no_par=no_par,
205
- )
206
- except Exception as e:
207
- logger.debug(e)
208
- raise
164
+ genmix(
165
+ location=location,
166
+ mixids=mixids,
167
+ compute_truth=compute_truth,
168
+ compute_segsnr=compute_segsnr,
169
+ cache=True,
170
+ show_progress=True,
171
+ force=True,
172
+ no_par=no_par,
173
+ )
209
174
 
210
175
  logger.info(f"Wrote {len(mixids)} mixtures to {location}")
211
176
  logger.info("")
@@ -224,4 +189,11 @@ def main() -> None:
224
189
 
225
190
 
226
191
  if __name__ == "__main__":
227
- main()
192
+ from sonusai import exception_handler
193
+ from sonusai.utils import register_keyboard_interrupt
194
+
195
+ register_keyboard_interrupt()
196
+ try:
197
+ main()
198
+ except Exception as e:
199
+ exception_handler(e)