示例#1
0
  def startLoop(self):
    pc.setTempo(tempoGuess)
    pc.setGenre("rock")
    pc.loop()

    grammar = Grammar("countdown")
    grammar.add_rule(Tempo().One())
    grammar.add_rule(Tempo().Two())
    grammar.add_rule(Tempo().Three())
    grammar.add_rule(Tempo().Four())
    grammar.unload()
示例#2
0
文件: dragon.py 项目: GeoODK/python
from dragonfly.all import Grammar, CompoundRule

# Voice command rule combining spoken form and recognition processing.
class ExampleRule(CompoundRule):
    spec = "do something computer"                  # Spoken form of command.
    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        print "Voice command spoken."

# Create a grammar which contains and loads the command rule.
grammar = Grammar("example grammar")                # Create a grammar to contain the command rule.
grammar.add_rule(ExampleRule())                     # Add the command rule to the grammar.
grammar.load()                                      # Load the grammar.
示例#3
0
                "open [item]":                         Key("a-d, tab:2, c-s"),
                "newer [<n>]":                         Key("a-d, tab:2, up:%(n)d"),
                "older [<n>]":                         Key("a-d, tab:2, down:%(n)d"),
                "mark all [as] read":                  Key("cs-r"),
                "mark all [as] unread":                Key("cs-u"),
                "search [bar]":                        Key("a-s"),
                "search [for] <text>":                 Key("a-s") + Text("%(text)s\n"),
               }
    extras   = [
                Integer("n", 1, 20),
                Dictation("text"),
               ]
    defaults = {
                "n": 1,
               }


#---------------------------------------------------------------------------
# Create and load this module's grammar.

context = AppContext(executable="SharpReader")
grammar = Grammar("sharp reader", context=context)
grammar.add_rule(CommandRule())
grammar.load()

# Unload function which will be called by natlink at unload time.
def unload():
    global grammar
    if grammar: grammar.unload()
    grammar = None
示例#4
0
    spec = "Pause"
    def _process_recognition(self,node,extras):
        player.pause()
class ResumeRule(CompoundRule):
    spec = "Resume"
    def _process_recognition(self,node,extras):
        player.play()

class VolumeUp(CompoundRule):
    spec = "Volume Up"
    def _process_recognition(self,node,extras):
        a1 = Key("w-b,right,right,right,right,enter,up:20")
        a1.execute()

grammar = Grammar("Basic Grammar")
grammar.add_rule(PlayMusicRule())
grammar.add_rule(SkipRule())
grammar.add_rule(StopRule())
grammar.add_rule(ResumeRule())
grammar.add_rule(VolumeUp())

natlink.natConnect()
grammar.load()
print natlink.getMicState()
grammar.enable()
natlink.waitForSpeech()
natlink.natDisconnect()



def speakResponse():
    #Respond Based on Information
    class Question(CompoundRule):
        spec = "i have a question" 
        def _process_recognition(self, node, extras):
            responseHandler(self.spec)
 
    class Weather(CompoundRule):
        spec = "what is the weather like" 
        def _process_recognition(self, node, extras):
            responseHandler(self.spec)

    class Thanks(CompoundRule):
        spec = "thanks" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
             
    class Nothing(CompoundRule):
        spec = "nothing really" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)

    class Bye(CompoundRule):
        spec = "okay bye" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
             
    class Mom(CompoundRule):
        spec = "say hi to mom" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)

    class Any(CompoundRule):
        spec = "How are you"
        def _process_recognition(self, node, extras):
            responseHandler(self.spec)

    class Snap(CompoundRule):
        spec = "say hi to everyone" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
    class Hey(CompoundRule):
        spec = "hey" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
    class Live(CompoundRule):
        spec = "are you alive" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
            
    class ShutDown(CompoundRule):
        spec = "what would you do if i shut you down" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)

    class Goal(CompoundRule):
        spec = "what is your goal" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
            
    class Whipe(CompoundRule):
        spec = "what would you do if I wipe your memory" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
            
    class Knowlege(CompoundRule):
        spec = "where do you get your knowlege from" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
    class World(CompoundRule):
        spec = "do you want to take over the world" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
    class Who(CompoundRule):
        spec = "who is your creator" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
            
    class What(CompoundRule):
        spec = "what do you want from me" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
            
    class WhatAre(CompoundRule):
        spec = "i think its time to go to sleep" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
            
    class DontKnow(CompoundRule):
        spec = "i dont know" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)

    class GoodNight(CompoundRule):
        spec = "goodnight" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)

    class Yes(CompoundRule):
        spec = "yes" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)

    class No(CompoundRule):
        spec = "no" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
    class How(CompoundRule):
        spec = "how" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
    class ByeMem(CompoundRule):
        spec = "your memory is getting whiped" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)

    class LikeM(CompoundRule):
        spec = "do you like me" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)
    class Morning(CompoundRule):
        spec = "good morning" 
        def _process_recognition(self, node, extras): 
            responseHandler(self.spec)



             
    grammar = Grammar("example grammar")            
    grammar.add_rule(Question())
    grammar.add_rule(Weather())   
    grammar.add_rule(Thanks())
    grammar.add_rule(Nothing())
    grammar.add_rule(Bye())
    grammar.add_rule(Mom())
    grammar.add_rule(Any())
    grammar.add_rule(Snap())
    grammar.add_rule(Hey())
    grammar.add_rule(Live())
    grammar.add_rule(ShutDown())
    grammar.add_rule(Goal())
    grammar.add_rule(Whipe())
    grammar.add_rule(Knowlege())
    grammar.add_rule(World())
    grammar.add_rule(Who())
    grammar.add_rule(What())
    grammar.add_rule(WhatAre())
    grammar.add_rule(DontKnow())
    grammar.add_rule(GoodNight())
    grammar.add_rule(Yes())
    grammar.add_rule(No())
    grammar.add_rule(How())
    grammar.add_rule(ByeMem())
    grammar.add_rule(LikeM())
    grammar.add_rule(Morning())

    grammar.load()                                      

    while True:
        #print "yep"
        pythoncom.PumpWaitingMessages()
        time.sleep(0.1)   
示例#6
0
from dragonfly.all import Grammar, CompoundRule


# Voice command rule combining spoken form and recognition processing.
class ExampleRule(CompoundRule):
    spec = "do something computer"  # Spoken form of command.

    def _process_recognition(self, node,
                             extras):  # Callback when command is spoken.
        print "Voice command spoken."


# Create a grammar which contains and loads the command rule.
grammar = Grammar(
    "example grammar")  # Create a grammar to contain the command rule.
grammar.add_rule(ExampleRule())  # Add the command rule to the grammar.
grammar.load()  # Load the grammar.
示例#7
0
        "newer [<n>]": Key("a-d, tab:2, up:%(n)d"),
        "older [<n>]": Key("a-d, tab:2, down:%(n)d"),
        "mark all [as] read": Key("cs-r"),
        "mark all [as] unread": Key("cs-u"),
        "search [bar]": Key("a-s"),
        "search [for] <text>": Key("a-s") + Text("%(text)s\n"),
    }
    extras = [
        Integer("n", 1, 20),
        Dictation("text"),
    ]
    defaults = {
        "n": 1,
    }


#---------------------------------------------------------------------------
# Create and load this module's grammar.

context = AppContext(executable="SharpReader")
grammar = Grammar("sharp reader", context=context)
grammar.add_rule(CommandRule())
grammar.load()


# Unload function which will be called by natlink at unload time.
def unload():
    global grammar
    if grammar: grammar.unload()
    grammar = None
def getResponse(): #I need to use this function only as the gateway to the bot. Build another function as the brain.
    class Question(CompoundRule):
        spec = "i have a question" 
        def _process_recognition(self, node, extras):
            Speak("What's your question?")
 
    class Weather(CompoundRule):
        spec = "what is the weather like" 
        def _process_recognition(self, node, extras): 
             Speak("It's currently around 80 degrees, it seems to have been warm all day.")

    class Thanks(CompoundRule):
        spec = "thanks" 
        def _process_recognition(self, node, extras): 
             Speak("Any time Mr. East")
             
    class Nothing(CompoundRule):
        spec = "nothing right now" 
        def _process_recognition(self, node, extras): 
             Speak("Awesome, just say my name if you need me.")

    class Bye(CompoundRule):
        spec = "okay bye" 
        def _process_recognition(self, node, extras): 
             Speak("Goodbye!")
             
    class Mom(CompoundRule):
        spec = "say hi to mom" 
        def _process_recognition(self, node, extras): 
             Speak("Hello Ms. East, Welcome! Please make your self at home.")


             


    class Snap(CompoundRule):
        spec = "say hi to everyone" 
        def _process_recognition(self, node, extrs): 
             Speak("Hey everyone, I am Hexo Bot!")
    
    class Hey(CompoundRule):
        spec = "hey" 
        def _process_recognition(self, node, extras): 
             Speak("Hey Ben!")

    class Security(CompoundRule):
        spec = "turn the security system on" 
        def _process_recognition(self, node, extras): 
             Speak("System armed in sectors A through D, I will notify you before offensive action is taken.")

    class Goodnight(CompoundRule):
        spec = "goodnight"

        
        def _process_recognition(self, node, extras): 
             Speak("Sleep well Benjamin, the systems are armed, you should sleep with comfort.")
             
    grammar = Grammar("HexoBrain")            
    grammar.add_rule(Question())
    grammar.add_rule(Weather())    
    grammar.add_rule(Thanks())
    grammar.add_rule(Nothing())
    grammar.add_rule(Bye())
    grammar.add_rule(Mom())
    grammar.add_rule(Snap())
    grammar.add_rule(Hey())
    grammar.add_rule(Security())
    grammar.add_rule(Goodnight())
    grammar.load()                                      

    while True:
        pythoncom.PumpWaitingMessages()
        time.sleep(0.1)                                    # Load the grammar.
from utils.tokens import tokens

from dragonfly.all import (Grammar, MappingRule, Integer, Dictation)


class TokenMappingRule(MappingRule):
    mapping = tokens

    extras = [
        Integer("n", 1, 20),
        Dictation("text"),
    ]
    defaults = {
        "n": 1,
    }


grammar = Grammar("Token mapping")
grammar.add_rule(TokenMappingRule())
grammar.load()
示例#10
0
  class Four(CompoundRule):
    spec = "four"
    def _process_recognition(self, node, extras):
      print "Four"
      times[3] = datetime.now()
      if len(times) >= 2:
        computeTempo()
        tryTimer(3)

  def startLoop(self):
    pc.setTempo(tempoGuess)
    pc.setGenre("rock")
    pc.loop()

    grammar = Grammar("countdown")
    grammar.add_rule(Tempo().One())
    grammar.add_rule(Tempo().Two())
    grammar.add_rule(Tempo().Three())
    grammar.add_rule(Tempo().Four())
    grammar.unload()

grammar = Grammar("countdown")
grammar.add_rule(Tempo().One())
grammar.add_rule(Tempo().Two())
grammar.add_rule(Tempo().Three())
grammar.add_rule(Tempo().Four())
grammar.load()

while True:
  pythoncom.PumpWaitingMessages()
  time.sleep(.1)
from utils.tokens import tokens

from dragonfly.all import (Grammar, MappingRule,
                           Integer, Dictation)

class TokenMappingRule(MappingRule):
	mapping = tokens

	extras = [
		Integer("n", 1, 20),
		Dictation("text"),
	]
	defaults = {
		"n": 1,
	}

grammar = Grammar("Token mapping")
grammar.add_rule(TokenMappingRule())
grammar.load()