sonusai 1.0.16__cp311-abi3-macosx_10_12_x86_64.whl → 1.0.18__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.
sonusai/datatypes.py CHANGED
@@ -88,16 +88,33 @@ class Effects(DataClassSonusAIMixin):
88
88
 
89
89
  class UniversalSNRGenerator:
90
90
  def __init__(self, raw_value: float | str) -> None:
91
- self._raw_value = str(raw_value)
92
- self.is_random = isinstance(raw_value, str) and raw_value.startswith("rand")
91
+ from sonusai.parse.choose import parse_choose_expression
92
+ from sonusai.parse.sequence import parse_sequence_expression
93
+
94
+ self.is_random = False
95
+ self._rand_obj = None
96
+
97
+ if isinstance(raw_value, str) and raw_value.startswith("rand"):
98
+ self.is_random = True
99
+ self._rand_directive = str(raw_value)
100
+ elif isinstance(raw_value, str) and raw_value.startswith("choose"):
101
+ self._rand_obj = parse_choose_expression(raw_value)
102
+ elif isinstance(raw_value, str) and raw_value.startswith("sequence"):
103
+ self._rand_obj = parse_sequence_expression(raw_value)
104
+ else:
105
+ self._raw_value = float(raw_value)
93
106
 
94
107
  @property
95
108
  def value(self) -> float:
96
109
  from sonusai.parse.rand import rand
97
110
 
98
111
  if self.is_random:
99
- return float(rand(self._raw_value))
100
- return float(self._raw_value)
112
+ return float(rand(self._rand_directive))
113
+
114
+ if self._rand_obj:
115
+ return float(self._rand_obj.next())
116
+
117
+ return self._raw_value
101
118
 
102
119
 
103
120
  class UniversalSNR(float):
@@ -590,7 +590,7 @@ class DatabaseManager:
590
590
  mix_rule=mix_rule,
591
591
  )
592
592
  )
593
- mixtures.extend(new_mixtures)
593
+ mixtures = new_mixtures
594
594
 
595
595
  # Update the mixid width
596
596
  with self.db(readonly=False) as c:
@@ -781,7 +781,7 @@ class DatabaseManager:
781
781
  mix_rule: str,
782
782
  ) -> list[Mixture]:
783
783
  if mix_rule == "none":
784
- return []
784
+ return mixtures
785
785
  if mix_rule.startswith("choose"):
786
786
  return self._additional_choose(
787
787
  effected_sources=effected_sources,
@@ -0,0 +1,68 @@
1
+ import pyparsing as pp
2
+
3
+ from ..utils.choice import RandomChoice
4
+
5
+
6
+ def parse_choose_expression(expression: str) -> RandomChoice:
7
+ """
8
+ Parse a string of the form "choose([1, 2, 3])" or "choose([1, 2, 3], repetition=True)"
9
+ and return a RandomChoice object with the parsed list and optional repetition parameter.
10
+
11
+ Args:
12
+ expression: String to parse, e.g., "choose([1, 2, 3])" or "choose([1, 2, 3], repetition=False)"
13
+
14
+ Returns:
15
+ RandomChoice object with parsed data and repetition settings
16
+
17
+ Raises:
18
+ pp.ParseException: If the string doesn't match the expected format
19
+ """
20
+ # Define grammar for parsing numbers, strings, and booleans
21
+ number = pp.pyparsing_common.number
22
+ quoted_string = pp.QuotedString('"') | pp.QuotedString("'")
23
+ boolean = pp.Keyword("True").setParseAction(lambda: True) | pp.Keyword("False").setParseAction(lambda: False)
24
+
25
+ # List element can be a number, quoted string, or boolean
26
+ list_element = number | quoted_string | boolean
27
+
28
+ # List definition: [item1, item2, ...]
29
+ list_def = pp.Suppress("[") + pp.Optional(pp.delimitedList(list_element)) + pp.Suppress("]")
30
+
31
+ # Repetition parameter: repetition=True, or repetition=False
32
+ repetition_param = pp.Keyword("repetition") + pp.Suppress("=") + boolean
33
+
34
+ # Function call: choose([...]) or choose([...], repetition=...)
35
+ function_call = (
36
+ pp.Keyword("choose")
37
+ + pp.Suppress("(")
38
+ + list_def
39
+ + pp.Optional(pp.Suppress(",") + repetition_param)
40
+ + pp.Suppress(")")
41
+ )
42
+
43
+ # Parse the expression
44
+ try:
45
+ result = function_call.parseString(expression, parseAll=True)
46
+
47
+ # Extract the list (everything between 'choose' and potential 'repetition')
48
+ data_list = []
49
+ repetition: bool = False
50
+
51
+ for item in result:
52
+ if item == "choose":
53
+ continue
54
+ elif item == "repetition":
55
+ break
56
+ else:
57
+ data_list.append(item)
58
+
59
+ # If repetition was specified, find its value
60
+ if "repetition" in result.as_list():
61
+ repetition_index = result.asList().index("repetition")
62
+ if repetition_index + 1 < len(result):
63
+ repetition = bool(result[repetition_index + 1])
64
+
65
+ return RandomChoice(data_list, repetition=repetition)
66
+
67
+ except pp.ParseException as e:
68
+ raise pp.ParseException(f"Invalid choose expression format: {e}") from e
@@ -0,0 +1,50 @@
1
+ import pyparsing as pp
2
+
3
+ from ..utils.choice import SequentialChoice
4
+
5
+
6
+ def parse_sequence_expression(expression: str) -> SequentialChoice:
7
+ """
8
+ Parse a string of the form "sequence([1, 2, 3])"
9
+ and return a SequentialChoice object with the parsed list.
10
+
11
+ Args:
12
+ expression: String to parse, e.g., "sequence([1, 2, 3])"
13
+
14
+ Returns:
15
+ SequentialChoice object with parsed data
16
+
17
+ Raises:
18
+ pp.ParseException: If the string doesn't match the expected format
19
+ """
20
+ # Define grammar for parsing numbers, strings, and booleans
21
+ number = pp.pyparsing_common.number
22
+ quoted_string = pp.QuotedString('"') | pp.QuotedString("'")
23
+ boolean = pp.Keyword("True").setParseAction(lambda: True) | pp.Keyword("False").setParseAction(lambda: False)
24
+
25
+ # List element can be a number, quoted string, or boolean
26
+ list_element = number | quoted_string | boolean
27
+
28
+ # List definition: [item1, item2, ...]
29
+ list_def = pp.Suppress("[") + pp.Optional(pp.delimitedList(list_element)) + pp.Suppress("]")
30
+
31
+ # Function call: sequence([...])
32
+ function_call = pp.Keyword("sequence") + pp.Suppress("(") + list_def + pp.Suppress(")")
33
+
34
+ # Parse the expression
35
+ try:
36
+ result = function_call.parseString(expression, parseAll=True)
37
+
38
+ # Extract the list (everything after 'sequence')
39
+ data_list = []
40
+
41
+ for item in result:
42
+ if item == "sequence":
43
+ continue
44
+ else:
45
+ data_list.append(item)
46
+
47
+ return SequentialChoice(data_list)
48
+
49
+ except pp.ParseException as e:
50
+ raise pp.ParseException(f"Invalid sequence expression format: {e}") from e
sonusai/rs.abi3.so CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sonusai
3
- Version: 1.0.16
3
+ Version: 1.0.18
4
4
  Requires-Dist: dataclasses-json >=0.6.7, <1.0.0
5
5
  Requires-Dist: docopt >=0.6.2, <1.0.0
6
6
  Requires-Dist: h5py >=3.12.1, <4.0.0
@@ -1,6 +1,6 @@
1
- sonusai-1.0.16.dist-info/METADATA,sha256=4rPDjq5Qs79248l_yin12alUioOX4j2zn_YzV_aNrF4,2601
2
- sonusai-1.0.16.dist-info/WHEEL,sha256=4-MxxhqCDAoFQQ2gzyecUreXPLf07ql-PG7vniU0rIA,105
3
- sonusai-1.0.16.dist-info/entry_points.txt,sha256=gw3C7Ih4fM4oJThb-dkERhdDtDzEHr6kZZVRVX0rkMk,91
1
+ sonusai-1.0.18.dist-info/METADATA,sha256=WuFcKlPEE4bBZHdWqvgRbX4vUS-H9N6Aeu4WfjEdIng,2601
2
+ sonusai-1.0.18.dist-info/WHEEL,sha256=4-MxxhqCDAoFQQ2gzyecUreXPLf07ql-PG7vniU0rIA,105
3
+ sonusai-1.0.18.dist-info/entry_points.txt,sha256=gw3C7Ih4fM4oJThb-dkERhdDtDzEHr6kZZVRVX0rkMk,91
4
4
  sonusai/mkwav.py,sha256=9fBlm14GlBCkz-hXvaM3rva2iVVSzQ45G7G0vmfP-wc,4309
5
5
  sonusai/metrics/calculate_metrics.py,sha256=jcAyEV6loenu4fU_EvwEkpKxOrP8-K9O3rwQGlE48IU,12475
6
6
  sonusai/metrics/calc_phase_distance.py,sha256=MFuBtGXb5qfQvRVciJ0Soz1w0GMSeJLBJud-aK4Loow,1870
@@ -36,7 +36,9 @@ sonusai/config/config.yml,sha256=Z7D4adzaK1TAUJyEJdjE-xdg67kHis4WXZ5UjAmyW2Q,804
36
36
  sonusai/config/source.py,sha256=hID2BbuaaqKjuJBcRSNTpiA6xtGd-TeSxSjzRDhD0Gc,10761
37
37
  sonusai/genmix.py,sha256=AaROzReE5vSRKZ3zqVOSdCpwANJHRHxQ8fWk6EcEVrE,5851
38
38
  sonusai/rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
+ sonusai/parse/choose.py,sha256=zkeTXNSl6h2xV6X01jep2dLvtJv1AjVOHvfma7Nh4aQ,2468
39
40
  sonusai/parse/parse_source_directive.py,sha256=HhQlqKXg6BoHaEGdVK7abRXLz1agi4M4RV-Z9ckuEpQ,4520
41
+ sonusai/parse/sequence.py,sha256=5j4glQlHPSH3SeyiHtAfxXjwNWm6c32ZkgdNTb9vvAI,1662
40
42
  sonusai/parse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
43
  sonusai/parse/rand.py,sha256=nKPqbN_w9xnm2_LBlTl1e6AZn4b89McR-CErxt6YBHM,8579
42
44
  sonusai/parse/expand.py,sha256=DAX1crIRKbcM61A7EpQRgvMj_d1ckRRjyl34tYYAQgg,4441
@@ -99,13 +101,13 @@ sonusai/speech/vctk.py,sha256=WInvRRRkZCW6t_NcZAJffJzgCbyetal-j2w0kKX5SDw,1527
99
101
  sonusai/speech/textgrid.py,sha256=WvsUeamKoYyXBNnNnZgug-xfTiq2Z6RnFc1u0swmqNw,2813
100
102
  sonusai/genmetrics.py,sha256=ekN7gocVNUfopOgxNbU7mTKahL3wSQSUM5wHOgbNtqU,6194
101
103
  sonusai/aawscd_probwrite.py,sha256=2ZhKoe1iFZ3nzbddEkdM93-CsbuJHE_VsuYyXInwaXE,3709
102
- sonusai/datatypes.py,sha256=XJ9jnWaEnrtwIEPCR_wCSyHetzbN3qWSUfI0W1_47Tg,9808
104
+ sonusai/datatypes.py,sha256=I9W7TFT2Lw1yugDW9dXwjw8bwqPEZ5tAztHfe0UGX0g,10455
103
105
  sonusai/genmixdb.py,sha256=ptwvhIhyMRhAIpZxNc3wZUosiyI9ZMcm5C4Wf9iL4mo,7043
104
106
  sonusai/lsdb.py,sha256=ochrLiWSdz1GjqX5Xw7JcH93fkt3nNurLY93tlAvJvA,5095
105
107
  sonusai/doc.py,sha256=mq52mun-QORFSZBO4KexLHkL7wjRsQTCiUbr5ZPN1Ts,1151
106
108
  sonusai/mixture/effects.py,sha256=o0KIOZ0va-LzrYpPt_ZzOwETieoMuEzJ0YlmJIOgnhA,10807
107
109
  sonusai/mixture/db.py,sha256=jbt499Dk-h9c8B7aIsBg-LCnVBJOY2VPkul-n9uJjgc,5683
108
- sonusai/mixture/generation.py,sha256=5l0050pzDvv8Kv7lw_AeXks94EjGmDQdAemueTfUJ5A,44402
110
+ sonusai/mixture/generation.py,sha256=EV1ofmubBiu7Er6igV7iaefoMoICzMcBzcBEGNcxoZA,44402
109
111
  sonusai/mixture/resample.py,sha256=jXqH6FrZ0mlhQ07XqPx88TT9elu3HHVLw7Q0a7Lh5M4,221
110
112
  sonusai/mixture/sox_effects.py,sha256=tndS9qrh3eJOTUPrufyWHCt3UqjbPuh81I4Lo4MNmDg,5328
111
113
  sonusai/mixture/pad_audio.py,sha256=KNxVQAejA0hblLOnMJgLS6lFaeE0n3tWQ5rclaHBnIY,1015
@@ -146,5 +148,5 @@ sonusai/rs.pyi,sha256=Y25n44pyE3vp92MiABKrcK3IWRyQ1JG1rZ4Ufqy2nC0,17
146
148
  sonusai/deprecated/plot.py,sha256=m9epn_RQn-EaarABKjjs2m2bGawxIP8o_KBXvx2s89A,17490
147
149
  sonusai/deprecated/tplot.py,sha256=jnOxiGwCQBy7ChkrNfbpwcgh5_L7Hjnkiyq7HL1HXFo,14651
148
150
  sonusai/deprecated/gentcst.py,sha256=QqyloM_JRck5NfIhGfttwkQeFJ9pmfXD0e0riCJCXu8,19964
149
- sonusai/rs.abi3.so,sha256=KJyZE1ySsUtb65V3_zEyIQwp3QU3ryyQOx-sawa29IY,432796
150
- sonusai-1.0.16.dist-info/RECORD,,
151
+ sonusai/rs.abi3.so,sha256=YskCuLNgLPv_8Wqil3aDv996C38spiP5Utkp7bEryxI,432796
152
+ sonusai-1.0.18.dist-info/RECORD,,