sonusai 1.0.16__cp311-abi3-macosx_10_12_x86_64.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 (150) hide show
  1. sonusai/__init__.py +170 -0
  2. sonusai/aawscd_probwrite.py +148 -0
  3. sonusai/audiofe.py +481 -0
  4. sonusai/calc_metric_spenh.py +1136 -0
  5. sonusai/config/__init__.py +0 -0
  6. sonusai/config/asr.py +21 -0
  7. sonusai/config/config.py +65 -0
  8. sonusai/config/config.yml +49 -0
  9. sonusai/config/constants.py +53 -0
  10. sonusai/config/ir.py +124 -0
  11. sonusai/config/ir_delay.py +62 -0
  12. sonusai/config/source.py +275 -0
  13. sonusai/config/spectral_masks.py +15 -0
  14. sonusai/config/truth.py +64 -0
  15. sonusai/constants.py +14 -0
  16. sonusai/data/__init__.py +0 -0
  17. sonusai/data/silero_vad_v5.1.jit +0 -0
  18. sonusai/data/silero_vad_v5.1.onnx +0 -0
  19. sonusai/data/speech_ma01_01.wav +0 -0
  20. sonusai/data/whitenoise.wav +0 -0
  21. sonusai/datatypes.py +383 -0
  22. sonusai/deprecated/gentcst.py +632 -0
  23. sonusai/deprecated/plot.py +519 -0
  24. sonusai/deprecated/tplot.py +365 -0
  25. sonusai/doc.py +52 -0
  26. sonusai/doc_strings/__init__.py +1 -0
  27. sonusai/doc_strings/doc_strings.py +531 -0
  28. sonusai/genft.py +196 -0
  29. sonusai/genmetrics.py +183 -0
  30. sonusai/genmix.py +199 -0
  31. sonusai/genmixdb.py +235 -0
  32. sonusai/ir_metric.py +551 -0
  33. sonusai/lsdb.py +141 -0
  34. sonusai/main.py +134 -0
  35. sonusai/metrics/__init__.py +43 -0
  36. sonusai/metrics/calc_audio_stats.py +42 -0
  37. sonusai/metrics/calc_class_weights.py +90 -0
  38. sonusai/metrics/calc_optimal_thresholds.py +73 -0
  39. sonusai/metrics/calc_pcm.py +45 -0
  40. sonusai/metrics/calc_pesq.py +36 -0
  41. sonusai/metrics/calc_phase_distance.py +43 -0
  42. sonusai/metrics/calc_sa_sdr.py +64 -0
  43. sonusai/metrics/calc_sample_weights.py +25 -0
  44. sonusai/metrics/calc_segsnr_f.py +82 -0
  45. sonusai/metrics/calc_speech.py +382 -0
  46. sonusai/metrics/calc_wer.py +71 -0
  47. sonusai/metrics/calc_wsdr.py +57 -0
  48. sonusai/metrics/calculate_metrics.py +395 -0
  49. sonusai/metrics/class_summary.py +74 -0
  50. sonusai/metrics/confusion_matrix_summary.py +75 -0
  51. sonusai/metrics/one_hot.py +283 -0
  52. sonusai/metrics/snr_summary.py +128 -0
  53. sonusai/metrics_summary.py +314 -0
  54. sonusai/mixture/__init__.py +15 -0
  55. sonusai/mixture/audio.py +187 -0
  56. sonusai/mixture/class_balancing.py +103 -0
  57. sonusai/mixture/constants.py +3 -0
  58. sonusai/mixture/data_io.py +173 -0
  59. sonusai/mixture/db.py +169 -0
  60. sonusai/mixture/db_datatypes.py +92 -0
  61. sonusai/mixture/effects.py +344 -0
  62. sonusai/mixture/feature.py +78 -0
  63. sonusai/mixture/generation.py +1116 -0
  64. sonusai/mixture/helpers.py +351 -0
  65. sonusai/mixture/ir_effects.py +77 -0
  66. sonusai/mixture/log_duration_and_sizes.py +23 -0
  67. sonusai/mixture/mixdb.py +1857 -0
  68. sonusai/mixture/pad_audio.py +35 -0
  69. sonusai/mixture/resample.py +7 -0
  70. sonusai/mixture/sox_effects.py +195 -0
  71. sonusai/mixture/sox_help.py +650 -0
  72. sonusai/mixture/spectral_mask.py +51 -0
  73. sonusai/mixture/truth.py +61 -0
  74. sonusai/mixture/truth_functions/__init__.py +45 -0
  75. sonusai/mixture/truth_functions/crm.py +105 -0
  76. sonusai/mixture/truth_functions/energy.py +222 -0
  77. sonusai/mixture/truth_functions/file.py +48 -0
  78. sonusai/mixture/truth_functions/metadata.py +24 -0
  79. sonusai/mixture/truth_functions/metrics.py +28 -0
  80. sonusai/mixture/truth_functions/phoneme.py +18 -0
  81. sonusai/mixture/truth_functions/sed.py +98 -0
  82. sonusai/mixture/truth_functions/target.py +142 -0
  83. sonusai/mkwav.py +135 -0
  84. sonusai/onnx_predict.py +363 -0
  85. sonusai/parse/__init__.py +0 -0
  86. sonusai/parse/expand.py +156 -0
  87. sonusai/parse/parse_source_directive.py +129 -0
  88. sonusai/parse/rand.py +214 -0
  89. sonusai/py.typed +0 -0
  90. sonusai/queries/__init__.py +0 -0
  91. sonusai/queries/queries.py +239 -0
  92. sonusai/rs.abi3.so +0 -0
  93. sonusai/rs.pyi +1 -0
  94. sonusai/rust/__init__.py +0 -0
  95. sonusai/speech/__init__.py +0 -0
  96. sonusai/speech/l2arctic.py +121 -0
  97. sonusai/speech/librispeech.py +102 -0
  98. sonusai/speech/mcgill.py +71 -0
  99. sonusai/speech/textgrid.py +89 -0
  100. sonusai/speech/timit.py +138 -0
  101. sonusai/speech/types.py +12 -0
  102. sonusai/speech/vctk.py +53 -0
  103. sonusai/speech/voxceleb.py +108 -0
  104. sonusai/utils/__init__.py +3 -0
  105. sonusai/utils/asl_p56.py +130 -0
  106. sonusai/utils/asr.py +91 -0
  107. sonusai/utils/asr_functions/__init__.py +3 -0
  108. sonusai/utils/asr_functions/aaware_whisper.py +69 -0
  109. sonusai/utils/audio_devices.py +50 -0
  110. sonusai/utils/braced_glob.py +50 -0
  111. sonusai/utils/calculate_input_shape.py +26 -0
  112. sonusai/utils/choice.py +51 -0
  113. sonusai/utils/compress.py +25 -0
  114. sonusai/utils/convert_string_to_number.py +6 -0
  115. sonusai/utils/create_timestamp.py +5 -0
  116. sonusai/utils/create_ts_name.py +14 -0
  117. sonusai/utils/dataclass_from_dict.py +27 -0
  118. sonusai/utils/db.py +16 -0
  119. sonusai/utils/docstring.py +53 -0
  120. sonusai/utils/energy_f.py +44 -0
  121. sonusai/utils/engineering_number.py +166 -0
  122. sonusai/utils/evaluate_random_rule.py +15 -0
  123. sonusai/utils/get_frames_per_batch.py +2 -0
  124. sonusai/utils/get_label_names.py +20 -0
  125. sonusai/utils/grouper.py +6 -0
  126. sonusai/utils/human_readable_size.py +7 -0
  127. sonusai/utils/keyboard_interrupt.py +12 -0
  128. sonusai/utils/load_object.py +21 -0
  129. sonusai/utils/max_text_width.py +9 -0
  130. sonusai/utils/model_utils.py +28 -0
  131. sonusai/utils/numeric_conversion.py +11 -0
  132. sonusai/utils/onnx_utils.py +155 -0
  133. sonusai/utils/parallel.py +162 -0
  134. sonusai/utils/path_info.py +7 -0
  135. sonusai/utils/print_mixture_details.py +60 -0
  136. sonusai/utils/rand.py +13 -0
  137. sonusai/utils/ranges.py +43 -0
  138. sonusai/utils/read_predict_data.py +32 -0
  139. sonusai/utils/reshape.py +154 -0
  140. sonusai/utils/seconds_to_hms.py +7 -0
  141. sonusai/utils/stacked_complex.py +82 -0
  142. sonusai/utils/stratified_shuffle_split.py +170 -0
  143. sonusai/utils/tokenized_shell_vars.py +143 -0
  144. sonusai/utils/write_audio.py +26 -0
  145. sonusai/utils/yes_or_no.py +8 -0
  146. sonusai/vars.py +47 -0
  147. sonusai-1.0.16.dist-info/METADATA +56 -0
  148. sonusai-1.0.16.dist-info/RECORD +150 -0
  149. sonusai-1.0.16.dist-info/WHEEL +4 -0
  150. sonusai-1.0.16.dist-info/entry_points.txt +3 -0
sonusai/genmixdb.py ADDED
@@ -0,0 +1,235 @@
1
+ """sonusai genmixdb
2
+
3
+ usage: genmixdb [-hvmdjn] LOC
4
+
5
+ options:
6
+ -h, --help
7
+ -v, --verbose Be verbose.
8
+ -m, --mix Save mixture data. [default: False].
9
+ -d, --dryrun Perform a dry run showing the processed config. [default: False].
10
+ -j, --json Save JSON version of database. [default: False].
11
+ -n, --nopar Do not run in parallel. [default: False].
12
+
13
+ Create mixture database data for training and evaluation. Optionally, also create mixture audio and feature/truth data.
14
+
15
+ genmixdb creates a database of training and evaluation feature and truth data generation information. It allows the
16
+ choice of audio neural-network feature types that are supported by the Aaware real-time front-end and truth data that is
17
+ synchronized frame-by-frame with the feature data.
18
+
19
+ For details, see sonusai doc.
20
+
21
+ """
22
+
23
+ from functools import partial
24
+ from random import seed
25
+
26
+ import yaml
27
+
28
+ from sonusai import logger
29
+ from sonusai.constants import SAMPLE_RATE
30
+ from sonusai.datatypes import Mixture
31
+ from sonusai.mixture import MixtureDatabase
32
+ from sonusai.mixture.data_io import write_cached_data
33
+ from sonusai.mixture.generation import DatabaseManager
34
+ from sonusai.mixture.generation import update_mixture
35
+ from sonusai.mixture.helpers import write_mixture_metadata
36
+ from sonusai.mixture.log_duration_and_sizes import log_duration_and_sizes
37
+ from sonusai.utils.parallel import par_track
38
+ from sonusai.utils.parallel import track
39
+
40
+
41
+ def genmixdb(
42
+ location: str,
43
+ save_mix: bool = False,
44
+ logging: bool = True,
45
+ show_progress: bool = False,
46
+ test: bool = False,
47
+ verbose: bool = False,
48
+ save_json: bool = False,
49
+ no_par: bool = False,
50
+ ) -> None:
51
+ dbm = DatabaseManager(location, test, verbose, logging)
52
+ mixdb = MixtureDatabase(location, test)
53
+
54
+ dbm.populate_top_table()
55
+ dbm.populate_class_label_table()
56
+ dbm.populate_class_weights_threshold_table()
57
+ dbm.populate_spectral_mask_table()
58
+ dbm.populate_truth_parameters_table()
59
+
60
+ seed(dbm.config["seed"])
61
+
62
+ if logging:
63
+ logger.debug(f"Seed: {dbm.config['seed']}")
64
+ logger.debug("Configuration:")
65
+ logger.debug(yaml.dump(dbm.config))
66
+
67
+ dbm.populate_source_file_table(show_progress)
68
+ dbm.populate_impulse_response_file_table(show_progress)
69
+
70
+ mixtures = dbm.generate_mixtures()
71
+ num_mixtures = len(mixtures)
72
+
73
+ if logging:
74
+ logger.info(f"Found {num_mixtures:,} mixtures to process")
75
+
76
+ total_duration = float(sum([mixture.samples for mixture in mixtures])) / SAMPLE_RATE
77
+
78
+ if logging:
79
+ log_duration_and_sizes(
80
+ total_duration=total_duration,
81
+ feature_step_samples=mixdb.feature_step_samples,
82
+ feature_parameters=mixdb.feature_parameters,
83
+ stride=mixdb.fg_stride,
84
+ desc="Estimated",
85
+ )
86
+ logger.info(
87
+ f"Feature shape: "
88
+ f"{mixdb.fg_stride} x {mixdb.feature_parameters} "
89
+ f"({mixdb.fg_stride * mixdb.feature_parameters} total parameters)"
90
+ )
91
+ logger.info(f"Feature samples: {mixdb.feature_samples} samples ({mixdb.feature_ms} ms)")
92
+ logger.info(f"Feature step samples: {mixdb.feature_step_samples} samples ({mixdb.feature_step_ms} ms)")
93
+ logger.info("")
94
+
95
+ # Fill in the details
96
+ if logging:
97
+ logger.info("Processing mixtures")
98
+ progress = track(total=num_mixtures, disable=not show_progress)
99
+ mixtures = par_track(
100
+ partial(
101
+ _process_mixture,
102
+ location=location,
103
+ save_mix=save_mix,
104
+ test=test,
105
+ ),
106
+ mixtures,
107
+ progress=progress,
108
+ no_par=no_par,
109
+ pass_index=True,
110
+ )
111
+ progress.close()
112
+
113
+ dbm.populate_mixture_table(mixtures=mixtures, show_progress=show_progress)
114
+
115
+ total_duration = float(mixdb.total_samples() / SAMPLE_RATE)
116
+
117
+ if logging:
118
+ log_duration_and_sizes(
119
+ total_duration=total_duration,
120
+ feature_step_samples=mixdb.feature_step_samples,
121
+ feature_parameters=mixdb.feature_parameters,
122
+ stride=mixdb.fg_stride,
123
+ desc="Actual",
124
+ )
125
+ logger.info("")
126
+
127
+ if not test and save_json:
128
+ if logging:
129
+ logger.info(f"Writing JSON version of database to {location}")
130
+ mixdb = MixtureDatabase(location)
131
+ mixdb.save()
132
+
133
+
134
+ def _process_mixture(
135
+ index: int,
136
+ mixture: Mixture,
137
+ location: str,
138
+ save_mix: bool,
139
+ test: bool,
140
+ ) -> Mixture:
141
+ mixdb = MixtureDatabase(location, test=test)
142
+ mixture.name = f"{index:0{mixdb.mixid_width}}"
143
+ mixture, genmix_data = update_mixture(mixdb, mixture, save_mix)
144
+
145
+ write = partial(write_cached_data, location=location, name="mixture", index=mixture.name)
146
+
147
+ if save_mix:
148
+ write(
149
+ items={
150
+ "sources": genmix_data.sources,
151
+ "source": genmix_data.source,
152
+ "noise": genmix_data.noise,
153
+ "mixture": genmix_data.mixture,
154
+ }
155
+ )
156
+
157
+ write_mixture_metadata(mixdb, mixture=mixture)
158
+
159
+ return mixture
160
+
161
+
162
+ def main() -> None:
163
+ from docopt import docopt
164
+
165
+ from sonusai import __version__ as sai_version
166
+ from sonusai.utils.docstring import trim_docstring
167
+
168
+ args = docopt(trim_docstring(__doc__), version=sai_version, options_first=True)
169
+
170
+ import time
171
+ from os import makedirs
172
+ from os import remove
173
+ from os.path import exists
174
+ from os.path import isdir
175
+ from os.path import join
176
+
177
+ import yaml
178
+
179
+ from sonusai import create_file_handler
180
+ from sonusai import initial_log_messages
181
+ from sonusai import logger
182
+ from sonusai import update_console_handler
183
+ from sonusai.config.config import load_config
184
+ from sonusai.utils.seconds_to_hms import seconds_to_hms
185
+
186
+ verbose = args["--verbose"]
187
+ save_mix = args["--mix"]
188
+ dryrun = args["--dryrun"]
189
+ save_json = args["--json"]
190
+ no_par = args["--nopar"]
191
+ location = args["LOC"]
192
+
193
+ start_time = time.monotonic()
194
+
195
+ if exists(location) and not isdir(location):
196
+ remove(location)
197
+
198
+ makedirs(location, exist_ok=True)
199
+
200
+ create_file_handler(join(location, "genmixdb.log"), verbose)
201
+ update_console_handler(verbose)
202
+ initial_log_messages("genmixdb")
203
+
204
+ if dryrun:
205
+ config = load_config(location)
206
+ logger.info("Dryrun configuration:")
207
+ logger.info(yaml.dump(config))
208
+ return
209
+
210
+ logger.info(f"Creating mixture database for {location}")
211
+ logger.info("")
212
+
213
+ genmixdb(
214
+ location=location,
215
+ save_mix=save_mix,
216
+ show_progress=True,
217
+ save_json=save_json,
218
+ verbose=verbose,
219
+ no_par=no_par,
220
+ )
221
+
222
+ end_time = time.monotonic()
223
+ logger.info(f"Completed in {seconds_to_hms(seconds=end_time - start_time)}")
224
+ logger.info("")
225
+
226
+
227
+ if __name__ == "__main__":
228
+ from sonusai import exception_handler
229
+ from sonusai.utils.keyboard_interrupt import register_keyboard_interrupt
230
+
231
+ register_keyboard_interrupt()
232
+ try:
233
+ main()
234
+ except Exception as e:
235
+ exception_handler(e)