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.
- sonusai/__init__.py +20 -29
- sonusai/aawscd_probwrite.py +18 -18
- sonusai/audiofe.py +93 -80
- sonusai/calc_metric_spenh.py +395 -321
- sonusai/data/genmixdb.yml +5 -11
- sonusai/{gentcst.py → deprecated/gentcst.py} +146 -149
- sonusai/{plot.py → deprecated/plot.py} +177 -131
- sonusai/{tplot.py → deprecated/tplot.py} +124 -102
- sonusai/doc/__init__.py +1 -1
- sonusai/doc/doc.py +112 -177
- sonusai/doc.py +10 -10
- sonusai/genft.py +93 -77
- sonusai/genmetrics.py +59 -46
- sonusai/genmix.py +116 -104
- sonusai/genmixdb.py +194 -153
- sonusai/lsdb.py +56 -66
- sonusai/main.py +23 -20
- sonusai/metrics/__init__.py +2 -0
- sonusai/metrics/calc_audio_stats.py +29 -24
- sonusai/metrics/calc_class_weights.py +7 -7
- sonusai/metrics/calc_optimal_thresholds.py +5 -7
- sonusai/metrics/calc_pcm.py +3 -3
- sonusai/metrics/calc_pesq.py +10 -7
- sonusai/metrics/calc_phase_distance.py +3 -3
- sonusai/metrics/calc_sa_sdr.py +10 -8
- sonusai/metrics/calc_segsnr_f.py +15 -17
- sonusai/metrics/calc_speech.py +105 -47
- sonusai/metrics/calc_wer.py +35 -32
- sonusai/metrics/calc_wsdr.py +10 -7
- sonusai/metrics/class_summary.py +30 -27
- sonusai/metrics/confusion_matrix_summary.py +25 -22
- sonusai/metrics/one_hot.py +91 -57
- sonusai/metrics/snr_summary.py +53 -46
- sonusai/mixture/__init__.py +19 -14
- sonusai/mixture/audio.py +4 -6
- sonusai/mixture/augmentation.py +37 -43
- sonusai/mixture/class_count.py +5 -14
- sonusai/mixture/config.py +292 -225
- sonusai/mixture/constants.py +41 -30
- sonusai/mixture/data_io.py +155 -0
- sonusai/mixture/datatypes.py +111 -108
- sonusai/mixture/db_datatypes.py +54 -70
- sonusai/mixture/eq_rule_is_valid.py +6 -9
- sonusai/mixture/feature.py +40 -38
- sonusai/mixture/generation.py +522 -389
- sonusai/mixture/helpers.py +217 -272
- sonusai/mixture/log_duration_and_sizes.py +16 -13
- sonusai/mixture/mixdb.py +669 -477
- sonusai/mixture/soundfile_audio.py +12 -17
- sonusai/mixture/sox_audio.py +91 -112
- sonusai/mixture/sox_augmentation.py +8 -9
- sonusai/mixture/spectral_mask.py +4 -6
- sonusai/mixture/target_class_balancing.py +41 -36
- sonusai/mixture/targets.py +69 -67
- sonusai/mixture/tokenized_shell_vars.py +23 -23
- sonusai/mixture/torchaudio_audio.py +14 -15
- sonusai/mixture/torchaudio_augmentation.py +23 -27
- sonusai/mixture/truth.py +48 -26
- sonusai/mixture/truth_functions/__init__.py +26 -0
- sonusai/mixture/truth_functions/crm.py +56 -38
- sonusai/mixture/truth_functions/datatypes.py +37 -0
- sonusai/mixture/truth_functions/energy.py +85 -59
- sonusai/mixture/truth_functions/file.py +30 -30
- sonusai/mixture/truth_functions/phoneme.py +14 -7
- sonusai/mixture/truth_functions/sed.py +71 -45
- sonusai/mixture/truth_functions/target.py +69 -106
- sonusai/mkwav.py +52 -85
- sonusai/onnx_predict.py +46 -43
- sonusai/queries/__init__.py +3 -1
- sonusai/queries/queries.py +100 -59
- sonusai/speech/__init__.py +2 -0
- sonusai/speech/l2arctic.py +24 -23
- sonusai/speech/librispeech.py +16 -17
- sonusai/speech/mcgill.py +22 -21
- sonusai/speech/textgrid.py +32 -25
- sonusai/speech/timit.py +45 -42
- sonusai/speech/vctk.py +14 -13
- sonusai/speech/voxceleb.py +26 -20
- sonusai/summarize_metric_spenh.py +11 -10
- sonusai/utils/__init__.py +4 -3
- sonusai/utils/asl_p56.py +1 -1
- sonusai/utils/asr.py +37 -17
- sonusai/utils/asr_functions/__init__.py +2 -0
- sonusai/utils/asr_functions/aaware_whisper.py +18 -12
- sonusai/utils/audio_devices.py +12 -12
- sonusai/utils/braced_glob.py +6 -8
- sonusai/utils/calculate_input_shape.py +1 -4
- sonusai/utils/compress.py +2 -2
- sonusai/utils/convert_string_to_number.py +1 -3
- sonusai/utils/create_timestamp.py +1 -1
- sonusai/utils/create_ts_name.py +2 -2
- sonusai/utils/dataclass_from_dict.py +1 -1
- sonusai/utils/docstring.py +6 -6
- sonusai/utils/energy_f.py +9 -7
- sonusai/utils/engineering_number.py +56 -54
- sonusai/utils/get_label_names.py +8 -10
- sonusai/utils/human_readable_size.py +2 -2
- sonusai/utils/model_utils.py +3 -5
- sonusai/utils/numeric_conversion.py +2 -4
- sonusai/utils/onnx_utils.py +43 -32
- sonusai/utils/parallel.py +40 -27
- sonusai/utils/print_mixture_details.py +25 -22
- sonusai/utils/ranges.py +12 -12
- sonusai/utils/read_predict_data.py +11 -9
- sonusai/utils/reshape.py +19 -26
- sonusai/utils/seconds_to_hms.py +1 -1
- sonusai/utils/stacked_complex.py +8 -16
- sonusai/utils/stratified_shuffle_split.py +29 -27
- sonusai/utils/write_audio.py +2 -2
- sonusai/utils/yes_or_no.py +3 -3
- sonusai/vars.py +14 -14
- {sonusai-0.18.9.dist-info → sonusai-0.19.5.dist-info}/METADATA +20 -21
- sonusai-0.19.5.dist-info/RECORD +125 -0
- {sonusai-0.18.9.dist-info → sonusai-0.19.5.dist-info}/WHEEL +1 -1
- sonusai/mixture/truth_functions/data.py +0 -58
- sonusai/utils/read_mixture_data.py +0 -14
- sonusai-0.18.9.dist-info/RECORD +0 -125
- {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
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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(
|
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
|
53
|
-
save_target: bool
|
54
|
-
compute_truth: bool
|
55
|
-
compute_segsnr: bool
|
56
|
-
force: bool
|
57
|
-
write: bool
|
58
|
-
|
59
|
-
|
60
|
-
MP_GLOBAL
|
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 =
|
78
|
-
results =
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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(
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
MP_GLOBAL
|
97
|
-
|
98
|
-
MP_GLOBAL
|
99
|
-
|
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
|
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 = [(
|
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((
|
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((
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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[
|
175
|
-
location = args[
|
176
|
-
mixids = args[
|
177
|
-
save_target = args[
|
178
|
-
compute_truth = args[
|
179
|
-
compute_segsnr = args[
|
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,
|
189
|
+
create_file_handler(join(location, "genmix.log"))
|
184
190
|
update_console_handler(verbose)
|
185
|
-
initial_log_messages(
|
191
|
+
initial_log_messages("genmix")
|
186
192
|
|
187
|
-
logger.info(f
|
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
|
196
|
-
logger.info(f
|
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
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
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
|
214
|
-
logger.info(f
|
215
|
-
logger.info(f
|
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
|
229
|
+
logger.info(f"segsnr: {human_readable_size(total_samples * 4, 1)}")
|
218
230
|
|
219
231
|
end_time = time.monotonic()
|
220
|
-
logger.info(f
|
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__ ==
|
236
|
+
if __name__ == "__main__":
|
225
237
|
main()
|