speech.say(phrase) # repeat it back
  if phrase == "stop now please":
    # The listener returned by listenfor() and listenforanything()
    # is also passed to the callback.
    listener.stoplistening()
listener3 = speech.listenforanything(L3callback)

# All callbacks get automatically executed on a single separate thread.
# Meanwhile, you can just do whatever with your program, or sleep.
# As long as your main program is running code, Listeners will keep listening.

import time
while listener3.islistening(): # till "stop now please" is heard
  time.sleep(1)

assert speech.islistening() # to at least one thing
print "Dictation is now stopped.  listeners 1 and 2 are still going."

listener1.stoplistening()
print "Now only listener 2 is going"

# Listen with listener2 for a while more, then turn it off.
time.sleep(30)

speech.stoplistening() # stop all remaining listeners
assert not speech.islistening()


# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
# If you don't have a specific set of phrases in mind, listenforanything() will
# run a callback every time anything is heard that doesn't match another Listener.
def L3callback(phrase, listener):
  speech.say(phrase) # repeat it back
  if phrase == "stop now please":
    # The listener returned by listenfor() and listenforanything()
    # is also passed to the callback.
    listener.stoplistening()
listener3 = speech.listenforanything(L3callback)

# All callbacks get automatically executed on a single separate thread.
# Meanwhile, you can just do whatever with your program, or sleep.
# As long as your main program is running code, Listeners will keep listening.

import time
while listener3.islistening(): # till "stop now please" is heard
  time.sleep(1)

assert speech.islistening() # to at least one thing
print ("Dictation is now stopped.  listeners 1 and 2 are still going.")

listener1.stoplistening()
print ("Now only listener 2 is going")

# Listen with listener2 for a while more, then turn it off.
time.sleep(30)

speech.stoplistening() # stop all remaining listeners
assert not speech.islistening()
      if hrdel<0: hrdel+=24
      if mndel<0: mndel+=60
      if scdel<0: scdel+=60
      delay = 3600*hrdel + 60*mndel + scdel
    print delay
    #Create a thread to execute action at given time
    Timer(delay, tmp).start()

while True:

    try:
        print "Please say the command out loud or press Ctrl+C twice to exit"
        speech.say("Please say the command out loud")
        input = speech.input("Please press Control plus C to type the command instead.") #"on fan zero nine three eight"
        print input,
        while speech.islistening():
            delta = speech.input(" - ")
            input += delta
            print delta,
        speech.say("You said: "+input)
        print ""
    except KeyboardInterrupt:
        speech.stoplistening()
        print ("Please type your command here; Press Ctrl+C to exit")
        try: input = raw_input()
        except KeyboardInterrupt: break

    if input!="": evaluate(input)
    input = ""