Baffled as to what is going wrong, as recognition works in simulation, just
not when speaking through DNS. This may suggest the problem is in how the
new element is compiled for DNS. But then the element does work okay
without repetition (and only single utterance).
This newly defined element recognises simply: word | "caps" word, where
word may be a single letter:
MyElement(ElementBase):
def decode(self, state):
state.decode_attempt(self)
word = state.word()
if word is None or (word=="stop"):
state.decode_failure(self)
return
if len(word)==1:
self._char += word.lower()
state.next(1)
else:
if word=="caps":
word=state.word(1)
self._char += str(word[0]).capitalize()
state.next(2)
else:
self._char += str(word[0]).lower()
state.next(1)
state.decode_success(self)
yield state
state.decode_failure(self)
return
As far as I know, the necessary calls - decode_attempt, next,
decode_success, decode_failure - have been included as required. There is
also decode_retry and decode_rollback, whose purpose it not fully
understood, but my hunch is, in this case, they're not required.
The compiler part for this element (in dragonfly.engines.compiler_natlink,
or dragonfly.engines.backend_natlink.compiler in Dragonfly v0.6.6b1), which
I've borrowed directly from that for Dictation:
def _compile_myelement(self, element, compiler):
compiler.add_rule("dgndictation", imported=True)
The grammar:
class TestRule(CompoundRule):
exported = True
spec = "word1<myelement>|word2<myelementREP>stop"
extras = [
MyElement(name="myelement"),
Repetition(MyElement(), min=1, max=20, name="myelementREP")
]
ruleRef = RuleRef(TestRule())
(and this is the element of an enclosing rule)
If anyone has any ideas as to why this code is getting stuck in DNS, I'd
greatly appreciate any comments, as I'm not hugely familiar as yet with the
parsing and compilation elements of Dragonfly.
Am using Dragonfly v0.6.6b1, which is more recent than the official release
version available from the Dragonfly website (v0.6.5), but am assuming that
the problem is more likely due to my code above rather than any bugs in the
beta.
Thanks
Jason