def initSpeech():
    r = sr.Recognizer()
    cmd = Commander()
    
    print("Listening")
    #play_audio('./audio/before.wav')
        
    with sr.Microphone() as source:                # use the default microphone as the audio source
        print("say something")
        audio = r.listen(source) 

    #play_audio('./audio/after.wav')
    command = ""

    try:
        command = r.recognize_google(audio)
    except:
        print("please repeat")

    print("Your command:" )
    print(command)

    if command in ["quit", "exit", "bye", "goodbye"]:
        global running 
        running = False

    command = command.replace("'", "")
    cmd.discover(command)
def initSpeak():
    print("Speaking")
    open_file('./audio/audio_initiate.wav')
    with sr.Microphone() as source:
        print("Say something")
        audio = r.listen(source)

    open_file('./audio/audio_end.wav')

    command = ""

    # recognize speech using Google Speech Recognition
    try:
        # for testing purposes, we're just using the default API key
        # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
        # instead of `r.recognize_google(audio)`
        # print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
        obj = engine.rootObjects()
        myObj = obj[0].findChild(QObject, 'mainPage')
        QMetaObject.invokeMethod(myObj, "updateQuestion", Qt.DirectConnection, Q_ARG("QVariant", r.recognize_google(audio)))
        command = r.recognize_google(audio)


    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))

    if command in quit:
        say("Bye")
        active = False
    else:
        commander = Commander()
        commander.discover(command)
  audio = r.listen(source)

  play_audio("./audio/nameOfFileEndTone.wav")

  command = ""

  try:
    command = r.recognize_goodle(audio)
  except:
    print("Could not be understood")
  
  
  print("Your command")
  print(command)
  if command in ["quit", "exit", "bye", "goodbye"]:
    global running # uses the global variable
    running = False
  cmd.discover(command)
  #say("Your said: " + command)

while running == True:
  initSpeech()

#file = pyglet.resource.media("audio/wet.mp3")
#file.play()

#pyglet.app.run()