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.
- sonusai/__init__.py +16 -3
- sonusai/audiofe.py +241 -77
- sonusai/calc_metric_spenh.py +71 -73
- sonusai/config/__init__.py +3 -0
- sonusai/config/config.py +61 -0
- sonusai/config/config.yml +20 -0
- sonusai/config/constants.py +8 -0
- sonusai/constants.py +11 -0
- sonusai/data/genmixdb.yml +21 -36
- sonusai/{mixture/datatypes.py → datatypes.py} +91 -130
- sonusai/deprecated/plot.py +4 -5
- sonusai/doc/doc.py +4 -4
- sonusai/doc.py +11 -4
- sonusai/genft.py +43 -45
- sonusai/genmetrics.py +25 -19
- sonusai/genmix.py +54 -82
- sonusai/genmixdb.py +88 -264
- sonusai/ir_metric.py +30 -34
- sonusai/lsdb.py +41 -48
- sonusai/main.py +15 -22
- sonusai/metrics/calc_audio_stats.py +4 -293
- sonusai/metrics/calc_class_weights.py +4 -4
- sonusai/metrics/calc_optimal_thresholds.py +8 -5
- sonusai/metrics/calc_pesq.py +2 -2
- sonusai/metrics/calc_segsnr_f.py +4 -4
- sonusai/metrics/calc_speech.py +25 -13
- sonusai/metrics/class_summary.py +7 -7
- sonusai/metrics/confusion_matrix_summary.py +5 -5
- sonusai/metrics/one_hot.py +4 -4
- sonusai/metrics/snr_summary.py +7 -7
- sonusai/metrics_summary.py +38 -45
- sonusai/mixture/__init__.py +4 -104
- sonusai/mixture/audio.py +10 -39
- sonusai/mixture/class_balancing.py +103 -0
- sonusai/mixture/config.py +251 -271
- sonusai/mixture/constants.py +35 -39
- sonusai/mixture/data_io.py +25 -36
- sonusai/mixture/db_datatypes.py +58 -22
- sonusai/mixture/effects.py +386 -0
- sonusai/mixture/feature.py +7 -11
- sonusai/mixture/generation.py +478 -628
- sonusai/mixture/helpers.py +82 -184
- sonusai/mixture/ir_delay.py +3 -4
- sonusai/mixture/ir_effects.py +77 -0
- sonusai/mixture/log_duration_and_sizes.py +6 -12
- sonusai/mixture/mixdb.py +910 -729
- sonusai/mixture/pad_audio.py +35 -0
- sonusai/mixture/resample.py +7 -0
- sonusai/mixture/sox_effects.py +195 -0
- sonusai/mixture/sox_help.py +650 -0
- sonusai/mixture/spectral_mask.py +2 -2
- sonusai/mixture/truth.py +17 -15
- sonusai/mixture/truth_functions/crm.py +12 -12
- sonusai/mixture/truth_functions/energy.py +22 -22
- sonusai/mixture/truth_functions/file.py +5 -5
- sonusai/mixture/truth_functions/metadata.py +4 -4
- sonusai/mixture/truth_functions/metrics.py +4 -4
- sonusai/mixture/truth_functions/phoneme.py +3 -3
- sonusai/mixture/truth_functions/sed.py +11 -13
- sonusai/mixture/truth_functions/target.py +10 -10
- sonusai/mkwav.py +26 -29
- sonusai/onnx_predict.py +240 -88
- sonusai/queries/__init__.py +2 -2
- sonusai/queries/queries.py +38 -34
- sonusai/speech/librispeech.py +1 -1
- sonusai/speech/mcgill.py +1 -1
- sonusai/speech/timit.py +2 -2
- sonusai/summarize_metric_spenh.py +10 -17
- sonusai/utils/__init__.py +7 -1
- sonusai/utils/asl_p56.py +2 -2
- sonusai/utils/asr.py +2 -2
- sonusai/utils/asr_functions/aaware_whisper.py +4 -5
- sonusai/utils/choice.py +31 -0
- sonusai/utils/compress.py +1 -1
- sonusai/utils/dataclass_from_dict.py +19 -1
- sonusai/utils/energy_f.py +3 -3
- sonusai/utils/evaluate_random_rule.py +15 -0
- sonusai/utils/keyboard_interrupt.py +12 -0
- sonusai/utils/onnx_utils.py +3 -17
- sonusai/utils/print_mixture_details.py +21 -19
- sonusai/utils/{temp_seed.py → rand.py} +3 -3
- sonusai/utils/read_predict_data.py +2 -2
- sonusai/utils/reshape.py +3 -3
- sonusai/utils/stratified_shuffle_split.py +3 -3
- sonusai/{mixture → utils}/tokenized_shell_vars.py +1 -1
- sonusai/utils/write_audio.py +2 -2
- sonusai/vars.py +11 -4
- {sonusai-0.20.3.dist-info → sonusai-1.0.2.dist-info}/METADATA +4 -2
- sonusai-1.0.2.dist-info/RECORD +138 -0
- sonusai/mixture/augmentation.py +0 -444
- sonusai/mixture/class_count.py +0 -15
- sonusai/mixture/eq_rule_is_valid.py +0 -45
- sonusai/mixture/target_class_balancing.py +0 -107
- sonusai/mixture/targets.py +0 -175
- sonusai-0.20.3.dist-info/RECORD +0 -128
- {sonusai-0.20.3.dist-info → sonusai-1.0.2.dist-info}/WHEEL +0 -0
- {sonusai-0.20.3.dist-info → sonusai-1.0.2.dist-info}/entry_points.txt +0 -0
sonusai/mixture/constants.py
CHANGED
@@ -1,56 +1,52 @@
|
|
1
|
-
import re
|
2
1
|
from importlib.resources import as_file
|
3
2
|
from importlib.resources import files
|
4
3
|
|
5
|
-
REQUIRED_CONFIGS =
|
4
|
+
REQUIRED_CONFIGS: tuple[str, ...] = (
|
6
5
|
"asr_configs",
|
7
6
|
"class_balancing",
|
8
|
-
"
|
7
|
+
"class_balancing_effect",
|
9
8
|
"class_indices",
|
10
9
|
"class_labels",
|
11
10
|
"class_weights_threshold",
|
12
11
|
"feature",
|
13
12
|
"impulse_responses",
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"noises",
|
13
|
+
"level_type",
|
14
|
+
"mixture_effects",
|
17
15
|
"num_classes",
|
18
|
-
"random_snrs",
|
19
16
|
"seed",
|
20
|
-
"
|
17
|
+
"sources",
|
21
18
|
"spectral_masks",
|
22
|
-
"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"
|
34
|
-
"
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
"
|
39
|
-
"
|
40
|
-
|
41
|
-
]
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
FLOAT_BYTES = 4
|
50
|
-
MIXDB_VERSION = 2
|
19
|
+
"summed_source_effects",
|
20
|
+
)
|
21
|
+
OPTIONAL_CONFIGS: tuple[str, ...] = ()
|
22
|
+
VALID_CONFIGS: tuple[str, ...] = REQUIRED_CONFIGS + OPTIONAL_CONFIGS
|
23
|
+
|
24
|
+
REQUIRED_SOURCES_CATEGORIES: tuple[str, ...] = (
|
25
|
+
"primary",
|
26
|
+
"noise",
|
27
|
+
)
|
28
|
+
|
29
|
+
REQUIRED_SOURCE_CONFIGS: tuple[str, ...] = (
|
30
|
+
"effects",
|
31
|
+
"files",
|
32
|
+
)
|
33
|
+
OPTIONAL_SOURCE_CONFIGS: tuple[str, ...] = ("truth_configs",)
|
34
|
+
REQUIRED_NON_PRIMARY_SOURCE_CONFIGS: tuple[str, ...] = (
|
35
|
+
"mix_rules",
|
36
|
+
"snrs",
|
37
|
+
)
|
38
|
+
VALID_PRIMARY_SOURCE_CONFIGS: tuple[str, ...] = REQUIRED_SOURCE_CONFIGS + OPTIONAL_SOURCE_CONFIGS
|
39
|
+
VALID_NON_PRIMARY_SOURCE_CONFIGS: tuple[str, ...] = VALID_PRIMARY_SOURCE_CONFIGS + REQUIRED_NON_PRIMARY_SOURCE_CONFIGS
|
40
|
+
|
41
|
+
REQUIRED_TRUTH_CONFIGS: tuple[str, ...] = (
|
42
|
+
"function",
|
43
|
+
"stride_reduction",
|
44
|
+
)
|
45
|
+
REQUIRED_ASR_CONFIGS: tuple[str, ...] = ("engine",)
|
51
46
|
|
52
|
-
|
53
|
-
|
47
|
+
MIXDB_VERSION = 3
|
48
|
+
MIXDB_NAME = "mixdb.db"
|
49
|
+
TEST_MIXDB_NAME = "mixdb_test.db"
|
54
50
|
|
55
51
|
with as_file(files("sonusai.data").joinpath("genmixdb.yml")) as path:
|
56
52
|
DEFAULT_CONFIG = str(path)
|
sonusai/mixture/data_io.py
CHANGED
@@ -13,13 +13,13 @@ def _get_pickle_name(location: str, index: str, item: str) -> str:
|
|
13
13
|
return join(location, index, item + ".pkl")
|
14
14
|
|
15
15
|
|
16
|
-
def read_hdf5_data(location: str, index: str, items: list[str] | str) -> Any:
|
16
|
+
def read_hdf5_data(location: str, index: str, items: list[str] | str) -> dict[str, Any]:
|
17
17
|
"""Read mixture, target, or noise data from an HDF5 file
|
18
18
|
|
19
19
|
:param location: Location of the file
|
20
20
|
:param index: Mixture, target, or noise index
|
21
21
|
:param items: String(s) of data to retrieve
|
22
|
-
:return:
|
22
|
+
:return: Dictionary of name: data
|
23
23
|
"""
|
24
24
|
from os.path import exists
|
25
25
|
from typing import Any
|
@@ -45,45 +45,39 @@ def read_hdf5_data(location: str, index: str, items: list[str] | str) -> Any:
|
|
45
45
|
if exists(h5_name):
|
46
46
|
try:
|
47
47
|
with h5py.File(h5_name, "r") as f:
|
48
|
-
result =
|
48
|
+
result = {item: _get_dataset(f, item) for item in items}
|
49
49
|
except Exception as e:
|
50
50
|
raise OSError(f"Error reading {h5_name}: {e}") from e
|
51
51
|
else:
|
52
|
-
result =
|
53
|
-
|
54
|
-
if len(items) == 1:
|
55
|
-
result = result[0]
|
52
|
+
result = {item: None for item in items}
|
56
53
|
|
57
54
|
return result
|
58
55
|
|
59
56
|
|
60
|
-
def write_hdf5_data(location: str, index: str, items:
|
57
|
+
def write_hdf5_data(location: str, index: str, items: dict[str, Any]) -> None:
|
61
58
|
"""Write mixture, target, or noise data to an HDF5 file
|
62
59
|
|
63
60
|
:param location: Location of the file
|
64
61
|
:param index: Mixture, target, or noise index
|
65
|
-
:param items:
|
62
|
+
:param items: Dictionary of name: data
|
66
63
|
"""
|
67
64
|
import h5py
|
68
65
|
|
69
|
-
if not isinstance(items, list):
|
70
|
-
items = [items]
|
71
|
-
|
72
66
|
h5_name = _get_hdf5_name(location, index)
|
73
67
|
with h5py.File(h5_name, "a") as f:
|
74
|
-
for
|
75
|
-
if
|
76
|
-
del f[
|
77
|
-
f.create_dataset(name=
|
68
|
+
for name, data in items.items():
|
69
|
+
if name in f:
|
70
|
+
del f[name]
|
71
|
+
f.create_dataset(name=name, data=data)
|
78
72
|
|
79
73
|
|
80
|
-
def read_pickle_data(location: str, index: str, items: list[str] | str) -> Any:
|
74
|
+
def read_pickle_data(location: str, index: str, items: list[str] | str) -> dict[str, Any]:
|
81
75
|
"""Read mixture, target, or noise data from a pickle file
|
82
76
|
|
83
77
|
:param location: Location of the file
|
84
78
|
:param index: Mixture, target, or noise index
|
85
79
|
:param items: String(s) of data to retrieve
|
86
|
-
:return:
|
80
|
+
:return: Dictionary of name: data
|
87
81
|
"""
|
88
82
|
import pickle
|
89
83
|
from os.path import exists
|
@@ -92,40 +86,35 @@ def read_pickle_data(location: str, index: str, items: list[str] | str) -> Any:
|
|
92
86
|
if not isinstance(items, list):
|
93
87
|
items = [items]
|
94
88
|
|
95
|
-
result:
|
89
|
+
result: dict[str, Any] = {}
|
96
90
|
for item in items:
|
97
91
|
pkl_name = _get_pickle_name(location, index, item)
|
98
92
|
if exists(pkl_name):
|
99
93
|
with open(pkl_name, "rb") as f:
|
100
|
-
result
|
94
|
+
result[item] = pickle.load(f) # noqa: S301
|
101
95
|
else:
|
102
|
-
result
|
103
|
-
|
104
|
-
if len(items) == 1:
|
105
|
-
result = result[0]
|
96
|
+
result[item] = None
|
106
97
|
|
107
98
|
return result
|
108
99
|
|
109
100
|
|
110
|
-
def write_pickle_data(location: str, index: str, items:
|
101
|
+
def write_pickle_data(location: str, index: str, items: dict[str, Any]) -> None:
|
111
102
|
"""Write mixture, target, or noise data to a pickle file
|
112
103
|
|
113
104
|
:param location: Location of the file
|
114
105
|
:param index: Mixture, target, or noise index
|
115
|
-
:param items:
|
106
|
+
:param items: Dictionary of name: data
|
116
107
|
"""
|
117
108
|
import pickle
|
118
109
|
from os import makedirs
|
119
110
|
from os.path import join
|
120
111
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
for item in items:
|
126
|
-
pkl_name = _get_pickle_name(location, index, item[0])
|
112
|
+
directory = join(location, index)
|
113
|
+
makedirs(directory, exist_ok=True)
|
114
|
+
for name, data in items.items():
|
115
|
+
pkl_name = _get_pickle_name(location, index, name)
|
127
116
|
with open(pkl_name, "wb") as f:
|
128
|
-
f.write(pickle.dumps(
|
117
|
+
f.write(pickle.dumps(data))
|
129
118
|
|
130
119
|
|
131
120
|
def clear_pickle_data(location: str, index: str, items: list[str] | str) -> None:
|
@@ -144,7 +133,7 @@ def clear_pickle_data(location: str, index: str, items: list[str] | str) -> None
|
|
144
133
|
Path(_get_pickle_name(location, index, item)).unlink(missing_ok=True)
|
145
134
|
|
146
135
|
|
147
|
-
def read_cached_data(location: str, name: str, index: str, items: list[str] | str) -> Any:
|
136
|
+
def read_cached_data(location: str, name: str, index: str, items: list[str] | str) -> dict[str, Any]:
|
148
137
|
"""Read cached data from a file
|
149
138
|
|
150
139
|
:param location: Location of the mixture database
|
@@ -158,13 +147,13 @@ def read_cached_data(location: str, name: str, index: str, items: list[str] | st
|
|
158
147
|
return read_pickle_data(join(location, name), index, items)
|
159
148
|
|
160
149
|
|
161
|
-
def write_cached_data(location: str, name: str, index: str, items:
|
150
|
+
def write_cached_data(location: str, name: str, index: str, items: dict[str, Any]) -> None:
|
162
151
|
"""Write data to a file
|
163
152
|
|
164
153
|
:param location: Location of the mixture database
|
165
154
|
:param name: Data name ('mixture', 'target', or 'noise')
|
166
155
|
:param index: Data index (mixture, target, or noise ID)
|
167
|
-
:param items:
|
156
|
+
:param items: Dictionary of name: data
|
168
157
|
"""
|
169
158
|
from os.path import join
|
170
159
|
|
sonusai/mixture/db_datatypes.py
CHANGED
@@ -1,56 +1,92 @@
|
|
1
1
|
from collections import namedtuple
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
SourceFileRecord = namedtuple(
|
4
|
+
"SourceFileRecord",
|
5
|
+
[
|
6
|
+
"id",
|
7
|
+
"category",
|
8
|
+
"class_indices",
|
9
|
+
"level_type",
|
10
|
+
"name",
|
11
|
+
"samples",
|
12
|
+
"speaker_id",
|
13
|
+
],
|
14
|
+
)
|
10
15
|
|
11
16
|
TopRecord = namedtuple(
|
12
17
|
"TopRecord",
|
13
18
|
[
|
14
19
|
"id",
|
15
|
-
"version",
|
16
20
|
"class_balancing",
|
17
21
|
"feature",
|
18
|
-
"
|
22
|
+
"mixid_width",
|
19
23
|
"num_classes",
|
20
24
|
"seed",
|
21
|
-
"mixid_width",
|
22
25
|
"speaker_metadata_tiers",
|
23
26
|
"textgrid_metadata_tiers",
|
27
|
+
"version",
|
24
28
|
],
|
25
29
|
)
|
26
30
|
|
27
|
-
ClassLabelRecord = namedtuple(
|
31
|
+
ClassLabelRecord = namedtuple(
|
32
|
+
"ClassLabelRecord",
|
33
|
+
[
|
34
|
+
"id",
|
35
|
+
"label",
|
36
|
+
],
|
37
|
+
)
|
28
38
|
|
29
|
-
ClassWeightsThresholdRecord = namedtuple(
|
39
|
+
ClassWeightsThresholdRecord = namedtuple(
|
40
|
+
"ClassWeightsThresholdRecord",
|
41
|
+
[
|
42
|
+
"id",
|
43
|
+
"threshold",
|
44
|
+
],
|
45
|
+
)
|
30
46
|
|
31
|
-
ImpulseResponseFileRecord = namedtuple(
|
47
|
+
ImpulseResponseFileRecord = namedtuple(
|
48
|
+
"ImpulseResponseFileRecord",
|
49
|
+
[
|
50
|
+
"id",
|
51
|
+
"delay",
|
52
|
+
"name",
|
53
|
+
],
|
54
|
+
)
|
32
55
|
|
33
56
|
SpectralMaskRecord = namedtuple(
|
34
57
|
"SpectralMaskRecord",
|
35
|
-
[
|
58
|
+
[
|
59
|
+
"id",
|
60
|
+
"f_max_width",
|
61
|
+
"f_num",
|
62
|
+
"t_max_percent",
|
63
|
+
"t_max_width",
|
64
|
+
"t_num",
|
65
|
+
],
|
36
66
|
)
|
37
67
|
|
38
|
-
|
68
|
+
SourceRecord = namedtuple(
|
69
|
+
"SourceRecord",
|
70
|
+
[
|
71
|
+
"id",
|
72
|
+
"effects",
|
73
|
+
"file_id",
|
74
|
+
"pre_tempo",
|
75
|
+
"repeat",
|
76
|
+
"snr",
|
77
|
+
"snr_gain",
|
78
|
+
"snr_random",
|
79
|
+
"start",
|
80
|
+
],
|
81
|
+
)
|
39
82
|
|
40
83
|
MixtureRecord = namedtuple(
|
41
84
|
"MixtureRecord",
|
42
85
|
[
|
43
86
|
"id",
|
44
87
|
"name",
|
45
|
-
"noise_file_id",
|
46
|
-
"noise_augmentation",
|
47
|
-
"noise_offset",
|
48
|
-
"noise_snr_gain",
|
49
|
-
"random_snr",
|
50
|
-
"snr",
|
51
88
|
"samples",
|
52
89
|
"spectral_mask_id",
|
53
90
|
"spectral_mask_seed",
|
54
|
-
"target_snr_gain",
|
55
91
|
],
|
56
92
|
)
|