sonusai 1.0.7__py3-none-any.whl → 1.0.9__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 +8 -7
- sonusai/audiofe.py +1 -1
- sonusai/calc_metric_spenh.py +9 -9
- sonusai/doc/doc.py +64 -61
- sonusai/genft.py +1 -1
- sonusai/genmetrics.py +3 -3
- sonusai/genmix.py +1 -1
- sonusai/genmixdb.py +1 -1
- sonusai/lsdb.py +1 -1
- sonusai/metrics_summary.py +7 -8
- sonusai/mixture/__init__.py +1 -1
- sonusai/mixture/db.py +163 -0
- sonusai/mixture/db_file.py +10 -0
- sonusai/mixture/effects.py +19 -52
- sonusai/mixture/generation.py +331 -391
- sonusai/mixture/mixdb.py +11 -68
- sonusai/mkwav.py +1 -1
- sonusai/onnx_predict.py +1 -1
- sonusai/utils/numeric_conversion.py +2 -2
- sonusai/utils/print_mixture_details.py +24 -28
- {sonusai-1.0.7.dist-info → sonusai-1.0.9.dist-info}/METADATA +2 -1
- {sonusai-1.0.7.dist-info → sonusai-1.0.9.dist-info}/RECORD +24 -22
- {sonusai-1.0.7.dist-info → sonusai-1.0.9.dist-info}/WHEEL +0 -0
- {sonusai-1.0.7.dist-info → sonusai-1.0.9.dist-info}/entry_points.txt +0 -0
sonusai/mixture/effects.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# sai_rand_choice_nr
|
4
|
-
# sai_sequence
|
5
|
-
# sai_expand
|
1
|
+
from numpy.ma.core import choose
|
2
|
+
from urllib3.filepost import choose_boundary
|
6
3
|
|
7
4
|
from ..datatypes import AudioT
|
8
5
|
from ..datatypes import Effects
|
@@ -28,40 +25,11 @@ def get_effect_rules(location: str, config: dict, test: bool = False) -> dict[st
|
|
28
25
|
return rules
|
29
26
|
|
30
27
|
|
31
|
-
def sai_expand(text: str) -> list[str]:
|
32
|
-
import re
|
33
|
-
|
34
|
-
# search pattern
|
35
|
-
pattern = re.compile(r"sai_expand\((.+?)\)")
|
36
|
-
|
37
|
-
# initialize with input
|
38
|
-
expanded = [text]
|
39
|
-
|
40
|
-
# look for pattern
|
41
|
-
result = re.search(pattern, text)
|
42
|
-
|
43
|
-
# if found
|
44
|
-
if result:
|
45
|
-
# remove entry we are expanding
|
46
|
-
expanded.pop()
|
47
|
-
|
48
|
-
# convert match into list stripped of whitespace
|
49
|
-
values = result.group(1).replace(" ", "").split(",")
|
50
|
-
|
51
|
-
# loop over values
|
52
|
-
for value in values:
|
53
|
-
# replace pattern with value
|
54
|
-
replacement = re.sub(pattern, value, text, count=1)
|
55
|
-
|
56
|
-
# extend result with expand of replacement (for handling multiple expands in a single rule)
|
57
|
-
expanded.extend(sai_expand(replacement))
|
58
|
-
|
59
|
-
return expanded
|
60
|
-
|
61
|
-
|
62
28
|
def _expand_effect_rules(expanded_rules: list[dict], rule: dict) -> list[dict]:
|
63
29
|
from copy import deepcopy
|
64
30
|
|
31
|
+
from .parse import sai_expand
|
32
|
+
|
65
33
|
for key in ("pre", "post"):
|
66
34
|
if key in rule:
|
67
35
|
value = rule[key]
|
@@ -274,8 +242,8 @@ def evaluate_sai_random_float(text: str) -> str:
|
|
274
242
|
return resolved
|
275
243
|
|
276
244
|
|
277
|
-
def
|
278
|
-
"""Evaluate '
|
245
|
+
def evaluate_sai_choose_ir(mixdb: MixtureDatabase, text: str) -> str:
|
246
|
+
"""Evaluate 'sai_choose' directive for ir
|
279
247
|
|
280
248
|
:param mixdb: Mixture database
|
281
249
|
:param text: Text to evaluate
|
@@ -285,11 +253,11 @@ def evaluate_sai_random_ir(mixdb: MixtureDatabase, text: str) -> str:
|
|
285
253
|
from random import choice
|
286
254
|
from random import randint
|
287
255
|
|
288
|
-
|
289
|
-
|
290
|
-
|
256
|
+
choose_pattern = re.compile(r"^ir sai_choose\(\)$")
|
257
|
+
choose_range_pattern = re.compile(r"^ir sai_choose\(([-+]?\d+),\s*([-+]?\d+)\)$")
|
258
|
+
choose_tag_pattern = re.compile(r"^ir sai_choose\((\w+)\)$")
|
291
259
|
|
292
|
-
def
|
260
|
+
def choose_range_repl(m) -> str:
|
293
261
|
lower = int(m.group(1))
|
294
262
|
upper = int(m.group(2))
|
295
263
|
if (
|
@@ -304,22 +272,22 @@ def evaluate_sai_random_ir(mixdb: MixtureDatabase, text: str) -> str:
|
|
304
272
|
raise ValueError(f"Invalid rule: '{text}'. Values must be integers between 0 and {mixdb.num_ir_files - 1}.")
|
305
273
|
return f"ir {randint(lower, upper)}" # noqa: S311
|
306
274
|
|
307
|
-
def
|
275
|
+
def choose_tag_repl(m) -> str:
|
308
276
|
return m.group(1)
|
309
277
|
|
310
|
-
if re.match(
|
278
|
+
if re.match(choose_pattern, text):
|
311
279
|
return f"ir {randint(0, mixdb.num_ir_files - 1)}" # noqa: S311
|
312
280
|
|
313
|
-
if re.match(
|
281
|
+
if re.match(choose_range_pattern, text):
|
314
282
|
try:
|
315
|
-
return f"ir {eval(re.sub(
|
283
|
+
return f"ir {eval(re.sub(choose_range_pattern, choose_range_repl, text))}" # noqa: S307
|
316
284
|
except Exception as e:
|
317
285
|
raise ValueError(
|
318
286
|
f"Invalid rule: '{text}'. Values must be integers between 0 and {mixdb.num_ir_files - 1}."
|
319
287
|
) from e
|
320
288
|
|
321
|
-
if re.match(
|
322
|
-
tag = re.sub(
|
289
|
+
if re.match(choose_tag_pattern, text):
|
290
|
+
tag = re.sub(choose_tag_pattern, choose_tag_repl, text)
|
323
291
|
if tag in mixdb.ir_tags:
|
324
292
|
return f"ir {choice(mixdb.ir_file_ids_for_tag(tag))}" # noqa: S311
|
325
293
|
|
@@ -336,10 +304,9 @@ def effects_from_rules(mixdb: MixtureDatabase, rules: Effects) -> Effects:
|
|
336
304
|
entries = getattr(effects, key)
|
337
305
|
for idx, entry in enumerate(entries):
|
338
306
|
if entry.find("sai_rand") != -1:
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
entries[idx] = evaluate_sai_random_float(entry)
|
307
|
+
entries[idx] = evaluate_sai_random_float(entry)
|
308
|
+
if entry.startswith("ir sai_choose"):
|
309
|
+
entries[idx] = evaluate_sai_choose_ir(mixdb, entry)
|
343
310
|
setattr(effects, key, entries)
|
344
311
|
|
345
312
|
return effects
|