python - Dragonfly 的模态命令

标签 python voice-recognition python-dragonfly

我正在使用dragonfly2 ,我想创建一个像 vim 一样的模态语法。我希望能够使用命令启用和禁用语法。

例如,如果我说 link,我有一个操作会在屏幕上显示带有 2 个字母标签的可能链接列表,因此我希望语法启用仅接受 2 个字母的模式- 字母词。特别是,在说 link 之后,我不希望语​​法接受任何正常命令,就像另一个 link 一样。

这可能吗?

最佳答案

啊哈!我刚刚在 someone else's grammar 中找到了这个:

class PythonEnabler(CompoundRule):
    spec = "Enable Python"                  # Spoken command to enable the Python grammar.

    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        pythonBootstrap.disable()
        pythonGrammar.enable()
        print "Python grammar enabled"

class PythonDisabler(CompoundRule):
    spec = "switch language"                  # spoken command to disable the Python grammar.

    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        pythonGrammar.disable()
        pythonBootstrap.enable()
        print "Python grammar disabled"

pythonBootstrap = Grammar("python bootstrap")                
pythonBootstrap.add_rule(PythonEnabler())
pythonBootstrap.load()

pythonGrammar = Grammar("python grammar")
pythonGrammar.add_rule(PythonTestRule())
pythonGrammar.add_rule(PythonCommentsSyntax())
pythonGrammar.add_rule(PythonControlStructures())
pythonGrammar.add_rule(PythonDisabler())

所以基本上,您可以简单地使用 some_grammar.disable()some_grammar.enable!

关于python - Dragonfly 的模态命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58111733/

相关文章:

python - 将 Pandas 数据框转置为数据范围

python - 强制 Numpy 数组中的元素在指定范围内

api - `Google Speech API Key` 在哪里?

使用给定单词列表的 Android 语音识别(在搜索小部件中)

python - 将语音数值传递给函数

python - 跳过列 pandas/多个以逗号分隔的空列表

python - 在 for 循环中创建多个列表

javascript - react JS : React Voice to Text Recognition

python - 使用 Dragonfly 禁用 Windows 语音识别