forked from dwks/kaldi-grammar-main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_all.py
61 lines (50 loc) · 1.91 KB
/
_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
50
51
52
53
54
55
56
57
58
59
60
61
# _all.py: main rule for kaldi-grammar-simple grammar
from dragonfly import *
import mode
import keyboard
import words
import programs
release = Key("shift:up, ctrl:up, alt:up")
class GlobalCommandRule(MappingRule):
mapping = {
"release mode": Function(lambda: mode.MultiMode.deactivate_all()),
}
alternatives = []
#alternatives.append(RuleRef(rule=GlobalCommandRule()))
alternatives.append(RuleRef(rule=keyboard.KeystrokeRule()))
#alternatives.append(RuleRef(rule=words.FormatRule()))
#alternatives.append(RuleRef(rule=words.ReFormatRule()))
#alternatives.append(RuleRef(rule=words.NopeFormatRule()))
#alternatives.append(RuleRef(rule=words.PhraseFormatRule()))
#alternatives.append(RuleRef(rule=programs.ProgramsRule()))
root_action = Alternative(alternatives)
sequence = Repetition(root_action, min=1, max=16, name="sequence")
class RepeatRule(CompoundRule):
# Here we define this rule's spoken-form and special elements.
spec = "<sequence> [[[and] repeat [that]] <n> times]"
extras = [
sequence, # Sequence of actions defined above.
IntegerRef("n", 1, 1)#, 100), # Times to repeat the sequence.
]
defaults = {
"n": 1, # Default repeat count.
}
def _process_recognition(self, node, extras): # @UnusedVariable
sequence = extras["sequence"] # A sequence of actions.
count = extras["n"] # An integer repeat count.
for i in range(count): # @UnusedVariable
for action in sequence:
action.execute()
release.execute()
grammar = Grammar("root rule")
grammar.add_rule(RepeatRule()) # Add the top-level rule.
grammar.load() # Load the grammar.
def unload():
"""Unload function which will be called at unload time."""
global grammar
if grammar:
grammar.unload()
grammar = None
if __name__ == '__main__':
#engine.list_available_microphones()
execfile('kaldi_module_loader_plus.py')