sonusai 1.0.9__py3-none-any.whl → 1.0.10__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.
@@ -0,0 +1,145 @@
1
+ """
2
+ Parse config rules
3
+
4
+ sai_expand(0, 5)
5
+ sai_expand(.0, 5)
6
+ sai_expand(0., 5)
7
+ sai_expand(0.0, 5)
8
+ sai_expand(0, .5)
9
+ sai_expand(.0, .5)
10
+ sai_expand(0., .5)
11
+ sai_expand(0.0, .5)
12
+ sai_expand(0, 5.)
13
+ sai_expand(.0, 5.)
14
+ sai_expand(0., 5.)
15
+ sai_expand(0.0, 5.)
16
+ sai_expand(0, 5.0)
17
+ sai_expand(.0, 5.0)
18
+ sai_expand(0., 5.0)
19
+ sai_expand(0.0, 5.0)
20
+
21
+ sai_rand(-1, 1)
22
+ sai_choose(repeat=False)
23
+ sai_choose(repeat=False, tag=tag)
24
+ sai_sequence()
25
+ sai_sequence(tag=tag)
26
+
27
+ sai_expand(0, sai_rand(-1, 1))
28
+ sai_expand(sai_rand(0, 4), 0)
29
+ sai_expand(sai_rand(0, 4), sai_rand(-1, 1))
30
+
31
+ sai_choose(num=1, unique=speaker_id, repeat=False)
32
+ sai_choose(num=1, repeat=False)
33
+ sai_choose(num=1, unique=speaker_id, repeat=True)
34
+ sai_choose(num=1, repeat=True)
35
+ sai_sequence(num=0)
36
+ sai_sequence(num=0, unique=speaker_id)
37
+
38
+ """
39
+
40
+ from dataclasses import dataclass
41
+
42
+
43
+ @dataclass
44
+ class Match:
45
+ group: str
46
+ span: tuple[int, int]
47
+
48
+ def start(self) -> int:
49
+ return self.span[0]
50
+
51
+ def end(self) -> int:
52
+ return self.span[1]
53
+
54
+
55
+ def find_sai_expand(text: str) -> list[Match]:
56
+ import re
57
+
58
+ results = []
59
+ matches = re.finditer(r"sai_expand\(", text)
60
+ if matches:
61
+ for match in matches:
62
+ s = match.start()
63
+ e = match.end()
64
+ num_lparen = 1
65
+ while num_lparen != 0 and e < len(text):
66
+ if text[e] == "(":
67
+ num_lparen += 1
68
+ elif text[e] == ")":
69
+ num_lparen -= 1
70
+ e += 1
71
+ if num_lparen != 0:
72
+ raise ValueError(f"Unbalanced parenthesis in '{text}'")
73
+
74
+ results.append(Match(group=text[s:e], span=(s, e)))
75
+
76
+ return results
77
+
78
+
79
+ def parse_sai_expand(text: str) -> list[str]:
80
+ """
81
+ expand_syntax ::= expand_keyword lparen expand_item next_expand_item+ rparen
82
+ expand_keyword ::= sai_expand
83
+ lparen ::= (
84
+ expand_item ::= expand_syntax | rand_syntax | number
85
+ rand_syntax ::= rand_keyword lparen rand_item comma rand_item rparen
86
+ rand_item ::= real number
87
+ comma ::= ,
88
+ number ::= real number or signed integer
89
+ next_item ::= comma item
90
+ rparen ::= )
91
+ """
92
+ import pyparsing as pp
93
+
94
+ lparen = pp.Literal("(")
95
+ rparen = pp.Literal(")")
96
+ comma = pp.Literal(",")
97
+
98
+ real_number = pp.pyparsing_common.real
99
+ signed_integer = pp.pyparsing_common.signed_integer
100
+ number = real_number | signed_integer
101
+
102
+ identifier = pp.Word(pp.alphanums + "_.-")
103
+
104
+ rand_literal = pp.Literal("sai_rand")
105
+ rand_expression = (rand_literal + lparen + number + comma + number + rparen).set_parse_action(
106
+ lambda tokens: "".join(map(str, tokens))
107
+ )
108
+
109
+ expand_literal = pp.Literal("sai_expand")
110
+ expand_args = pp.DelimitedList(rand_expression | identifier, min=1)
111
+ expand_expression = expand_literal + lparen + expand_args("args") + rparen
112
+
113
+ try:
114
+ result = expand_expression.parse_string(text)
115
+ except pp.ParseException as e:
116
+ raise ValueError(f"Could not parse '{text}'") from e
117
+
118
+ return list(result.args)
119
+
120
+
121
+ def sai_expand(text: str) -> list[str]:
122
+ # initialize with input
123
+ expanded = [text]
124
+
125
+ # look for pattern
126
+ matches = find_sai_expand(text)
127
+
128
+ # if not found, early exit
129
+ if not matches:
130
+ return expanded
131
+
132
+ # remove entry we are expanding
133
+ expanded.pop()
134
+
135
+ # start with the innermost match
136
+ match = matches[-1]
137
+ prelude = text[: match.start()]
138
+ postlude = text[match.end() :]
139
+
140
+ # loop over parsed expand values
141
+ for value in parse_sai_expand(match.group):
142
+ # extend result with expand of replacement (for handling multiple expands in a single rule)
143
+ expanded.extend(sai_expand(prelude + value + postlude))
144
+
145
+ return expanded
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sonusai
3
- Version: 1.0.9
3
+ Version: 1.0.10
4
4
  Summary: Framework for building deep neural network models for sound, speech, and voice AI
5
5
  Home-page: https://aaware.com
6
6
  License: GPL-3.0-only
@@ -63,6 +63,7 @@ sonusai/mixture/ir_effects.py,sha256=PqiqD4PS42-7kD6ESnsZi2a3tnKCFa4E0xqUujRBvGg
63
63
  sonusai/mixture/log_duration_and_sizes.py,sha256=3ekS27IMKlnxIkQAmprzmBnzHOpRjZh3d7maL2VqWQU,927
64
64
  sonusai/mixture/mixdb.py,sha256=5YI0zKisFw_B-jKpB-Y1EYlJ8pHQDvOQLs9LEe0gT1w,84905
65
65
  sonusai/mixture/pad_audio.py,sha256=KNxVQAejA0hblLOnMJgLS6lFaeE0n3tWQ5rclaHBnIY,1015
66
+ sonusai/mixture/parse.py,sha256=nqhjuR-J7_3wlGhVitYFvQwLJ1sclU8WZrVF0SyW2Cw,3700
66
67
  sonusai/mixture/resample.py,sha256=jXqH6FrZ0mlhQ07XqPx88TT9elu3HHVLw7Q0a7Lh5M4,221
67
68
  sonusai/mixture/sox_effects.py,sha256=tndS9qrh3eJOTUPrufyWHCt3UqjbPuh81I4Lo4MNmDg,5328
68
69
  sonusai/mixture/sox_help.py,sha256=DOTMBZfYQs3bXrqra25iH92lJFhqcGe9M1am4OrKkBY,29855
@@ -133,7 +134,7 @@ sonusai/utils/tokenized_shell_vars.py,sha256=EDrrAgz5lJ0RBAjLcTJt1MeyjhbNZiqXkym
133
134
  sonusai/utils/write_audio.py,sha256=IHzrJoFtFcea_J6wo6QSiojRkgnNOzAEcg-z0rFV7nU,810
134
135
  sonusai/utils/yes_or_no.py,sha256=0h1okjXmDNbJp7rZJFR2V-HFU1GJDm3YFTUVmYExkOU,263
135
136
  sonusai/vars.py,sha256=m8pdgfR4A6A9TCGf_rok6jPAT5BgrEsYXTSISIh1nrI,1163
136
- sonusai-1.0.9.dist-info/METADATA,sha256=PnNdFaS3cIoP8dZEDP6bKK-QoR5W_rV-z5OwEhxhlQs,2694
137
- sonusai-1.0.9.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
138
- sonusai-1.0.9.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
139
- sonusai-1.0.9.dist-info/RECORD,,
137
+ sonusai-1.0.10.dist-info/METADATA,sha256=kliBuHLQIEAUTsv9Hav0VWo1IGQxpTao5bl233yOnaQ,2695
138
+ sonusai-1.0.10.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
139
+ sonusai-1.0.10.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
140
+ sonusai-1.0.10.dist-info/RECORD,,