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

Mimic extra type being handled incorrectly? #35

Closed synkarius closed 9 years ago

synkarius commented 9 years ago

If I use the example Mimic rule from the documentation, I get the following error:

File "C:\Python27\lib\site-packages\dragonfly\actions\action_mimic.py", line 107, in _execute words += extra.words TypeError: can only concatenate tuple (not "list") to tuple

Voxellence commented 9 years ago

The Mimic action class in Dragonfly is pretty much the same thing as HeardWord in Advanced Scripting. It is defined in the file action_mimic.py where you can see that it inherits from ActionBase which is in the file action_base.py and is documented as "Base class for Dragonfly's action classes". Here is a minimalistic example that fleshes out the documentation to create a working script:

from dragonfly import Grammar, MappingRule, Mimic

# The meat of the macro consists of two lines of code:
mimic_action = Mimic("hello", "world", r"!\exclamation-mark")
mimic_rule = MappingRule(mapping = { "say hello": mimic_action })

# From here to the end is nothing but the usual boilerplate code:
grammar = Grammar("mimic example")
grammar.add_rule(mimic_rule)
grammar.load()

def unload():
    global grammar
    if grammar: grammar.unload()
    grammar = None

You can see that the words "say hello" are mapped to the Mimic action instance. If you have this script active with Notepad in the foreground and you dictate "say hello", the text "Hello world!" will be typed into Notepad. Notice that since the mimicked words are interpreted as text, the capitalization flag is applied to the word "hello", causing it to be sent to Notepad as "Hello".

synkarius commented 9 years ago

Your example works fine. Did you try the example from the documentation?

from dragonfly import (Repeat, Mimic, Dictation, Grammar,  MappingRule, IntegerRef)

class ExampleRule(MappingRule):
    mapping  = {
                "mimic recognition <text> [<n> times]":
                    Mimic(extra="text") * Repeat(extra="n"),
               }
    extras   = [
                IntegerRef("n", 1, 10),
                Dictation("text"),
               ]
    defaults = {
                "n": 1,
               }
grammar = Grammar("mimic example")
grammar.add_rule(ExampleRule())
grammar.load()

def unload():
    global grammar
    if grammar: grammar.unload()
    grammar = None

With this example from the documentation, and the latest version of Dragonfly, I get a

TypeError: can only concatenate tuple (not "list") to tuple

on line 107 of action_mimic.py.

Voxellence commented 9 years ago

When I try the Mimic example you mention that uses a MappingRule, it works as expected. For instance, if I dictate the words "mimic recognition test this macro five times" with Notepad as the foreground application, the following text appears in my Notepad window: Test this macro test this macro test this macro test this macro test this macro

I can only suspect that your Dragonfly installation is not as it should be. I know that in my own case, getting it installed correctly was a pain in the ass until I managed to gather the right voodoo to make it happen. Essentially it boiled down to me having to use pip to get it right because the ez_setup.py file looks for a setuptools file with version 0.6c9 which doesn't exist in Python 2.7. Using pip, it just worked and I didn't have to pull out any more hair than I had already pulled out. I've seen someone saying that you can just copy the files somehow and it will work, but pip worked for me and I've had enough installation stress already that I don't care to mess with it. If anyone would like to enlighten us on how to tell Python where the files are manually, that would be great. Oh, and by the way, I had used TortoiseSVN to get the files onto my machine from the Google site; I did not download them from github, although it apparently doesn't matter since the source version I have is the same as the one on github.

It was only recently that I installed Dragonfly on Windows 8.1, which really was no different than installing it on Windows 7, except that I was re-installing a version on which I had modified some of the source code for my own purposes. The stuff I modified, though, had no effect on installation, so it was no problem.

Good luck.

synkarius commented 9 years ago

That's pretty strange. I doubt it has to do with my installation though. I have Dragonfly installed through what I'm pretty sure is the intended procedure: python setup.py install. Before Dragonfly moved here to Github, I had installed it two other ways, one with pip, as you mentioned, and the other with the Windows installer from the Pypi site. Both of those ways also had this problem. Only two lines have changed in action_mimic.py since the most recent Google Code version, and they have nothing to do with this problem.

Can anyone else confirm or disconfirm?

Voxellence commented 9 years ago

I'm not quite sure why you would doubt that your installation is the problem since other people's installations are working correctly. As I've said, I'm quite sure that I have the most recent version, which I believe was released quite a long time ago, and indeed why would Mr. Butcher leave his last released version as a broken one, especially since he has gone to the trouble of moving his source code to github?

synkarius commented 9 years ago

Actually, all we've verified so far is that your installation works correctly. Hence me asking what others say.

Since your original message suggested that I diff files, I have. (It's not hard with a tool like WinMerge.) There is zero difference between my installation and this Github repository (at time of writing) except that I am missing a few example files and files for alternate languages. Report here: http://explosionduck.com/documents/reports/winmerge.html This is to be expected because I reinstalled from this repository two days ago.

Also, since we're diffing files, the Google Code version is not the most up-to-date version, nor was it "broken", but it also wasn't bug free, as you can see from all the closed issues in this repository.

But I digress. Can anyone else confirm or disconfirm?

t4ngo commented 9 years ago

This problem was caused by earlier changes to the DictationContainer base class causing it to provide words as a list instead of a tuple. I've fixed this issue in commits dac2b292fd7e69cda7fe66069ed0a649e8a2f136 and 9f16029722a03d661372905782490e452cfd639a.

synkarius commented 9 years ago

Thanks!