t4ngo / dragonfly

ARCHIVED! - Speech recognition framework allowing powerful Python-based scripting and extension of Dragon NaturallySpeaking (DNS) and Windows Speech Recognition (WSR)
GNU Lesser General Public License v3.0
364 stars 82 forks source link

_fruit_toggle.py example doesn't work, CompoundRules broken? #29

Open jgarvin opened 9 years ago

jgarvin commented 9 years ago

Speaking, "I like bananas" or "I like apples" does nothing.

If I copy and paste the MappingRule from the outlook_example.py into _fruit_toggle.py, and add the rule to the same grammar object as the apple/banana rule, the phrases in it are recognized correctly. So dragon/natlink are working. So it appears just plain CompoundRules are broken?

jgarvin commented 9 years ago

I went ahead and wrote a MappingRule version which works just to be sure:

#
# This file is part of Dragonfly.
# (c) Copyright 2007, 2008 by Christo Butcher
# Licensed under the LGPL.
#
#   Dragonfly is free software: you can redistribute it and/or modify it 
#   under the terms of the GNU Lesser General Public License as published 
#   by the Free Software Foundation, either version 3 of the License, or 
#   (at your option) any later version.
#
#   Dragonfly is distributed in the hope that it will be useful, but 
#   WITHOUT ANY WARRANTY; without even the implied warranty of 
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
#   Lesser General Public License for more details.
#
#   You should have received a copy of the GNU Lesser General Public 
#   License along with Dragonfly.  If not, see 
#   <http://www.gnu.org/licenses/>.
#

"""
    This module demonstrates the use of the Dragonfly speech recognition
    library.

"""

from dragonfly import (Grammar, CompoundRule, Dictation, MappingRule, Key, ActionBase)
from dragonfly import get_engine
import logging
import sys
logging.basicConfig()

print "Fruit script really does execute!"

grammar = Grammar("fruit toggle")

class B(ActionBase):
    def _execute(self, data=None):
        print "I like bananas"
        apple_rule.enable()
        banana_rule.disable()

class A(ActionBase):
    def _execute(self, data=None):
        print "I like apples"
        banana_rule.enable()
        apple_rule.disable()

banana_rule = MappingRule(
    name="bananas",
    mapping={
             "I like bananas":                   B(),
            },
    )

apple_rule = MappingRule(
    name="apples",
    mapping={
             "I like apples":                   A(),
            },
    )

grammar.add_rule(apple_rule)
grammar.add_rule(banana_rule)

#---------------------------------------------------------------------------
# Load the grammar instance and define how to unload it.

grammar.load()
get_engine().set_exclusiveness(grammar, 1)

# Unload function which will be called by natlink at unload time.
def unload():
    global grammar
    if grammar: grammar.unload()
    grammar = None
tylercal commented 9 years ago

The fruit toggle example works fine for me in WSR.

synkarius commented 9 years ago

DNS user here, I can confirm this bug. Actually, for me it works inconsistently. If I alternate between saying, "I like apples" and "I like bananas", sometimes it triggers the rule and sometimes it doesn't, and just prints the text of what I said.

Dragonfly 0.6.6b1 Natlink 4.1mike Dragon NaturallySpeaking 12.0 Windows 7

jgarvin commented 9 years ago

@synkarius Does the MappingRule version work for you?

synkarius commented 9 years ago

@jgarvin Yes, and without the inconsistency.

Voxellence commented 9 years ago

The fruit_toggle.py example works just fine as-is, meaning two CompoundRule instances added to a single Grammar. Thus, I find that CompoundRule is not broken and there is no need to use MappingRule or to otherwise modify the original macro in any substantive way. I find that this script produces consistent alternation of the active rule. It works whether I dictate optional text, or whether I do not.

To verify this in a scientific way, I just now dictated "I like bananas" and then "I like apples" 10 times in a row, for a total of 20 sequential recognitions. At that point I was sufficiently convinced that there is not a problem.

Dragonfly 0.6.6b1 Natlink 4.1mike Dragon NaturallySpeaking Professional 12.50.000.142 Windows 8.1 (Based upon what I have read regarding application compatibility and the behavior of the Dictation Box, I have no intention of upgrading to version 13 anytime soon.)