Пример #1
0
    def callback(self, recognizer, audio):
        from App.Core import user_manager
        user_manager.get_user()
        debug("I heard something")
        # received audio data, now we'll recognize it 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)`
            command = recognizer.recognize_wit(audio, api_key)
            debug("User said: " + command)
            aliasses = {'poepie', 'poppie', 'poppy', 'moppie', 'pappie'}

            for alias in aliasses:
                if str.lower(_("Hello") + alias) in str.lower(command).replace(
                        " ", ""):
                    tts.say(
                        _("Hello %s, what can I do for you?") %
                        user_manager.user.name)
                    self.command_centre.start()

        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))
Пример #2
0
 def ask(self):
     if self.is_repeat_question is True:
         tts.say(_("I'll repeat the question"))
         debug("Repeating question")
     question_text = self.question.ask_question()
     debug("Question: " + question_text)
     tts.say(question_text)
Пример #3
0
 def execute(self):
     weather.set_location(self.response.location)
     current_weather = weather.get_current_weather()
     temp = current_weather.get_temperature('celsius')
     tts.say("Het wordt vandaag %s en %s graden in %s" % (
         current_weather.get_detailed_status(),
         math.floor(temp['temp_max']),
         self.response.location,
     ))
Пример #4
0
 def confirming_answer(self):
     if hasattr(self.response, 'text'):
         tts.say(
             _("You've answered %s, is that right?") % self.response.text)
     confirmation_intent_response = intent_handler.wait_for_answer()
     if hasattr(confirmation_intent_response, 'intent'):
         if confirmation_intent_response.intent == 'confirmation_confirm':
             debug("Confirmed")
             return True
         elif confirmation_intent_response.intent == 'confirmation_deny':
             debug("Repeat question")
             tts.say(_("I'll repeat the question"))
             return False
Пример #5
0
 def gstt():
     try:
         with sr.Microphone(sample_rate = sample_rate,chunk_size = chunk_size) as source:
             print("say something")
             tts.say('give your command')
             r.adjust_for_ambient_noise(source)
             audio = r.listen(source)
             if(audio):
             # 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)`
                return r.recognize_google(audio)
             else:
                return NULL
     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))
Пример #6
0
    def start_conversation(self):
        end_of_conversation = False

        starting_question = self.conversation.start()

        if issubclass(starting_question.__class__, Question):
            self.question = QuestionHandler(starting_question)
        else:
            debug(
                "Starting node is not of type question. Stopping conversation")
            return

        while end_of_conversation is False:
            self.question.ask()

            listener = ConversationListener()
            response = listener.listen()

            response_handler = ResponseHandler(response=response)
            if issubclass(self.question.question.__class__, FreeAnswer):
                response_handler.free_text_answer_allowed = True
            question_context = response_handler.get_question_context(
                conversation=self.conversation,
                current_question=self.question.question)

            if isinstance(question_context, Success):
                tts.say(question_context.intermediate_text)
                self.question.set(question=question_context.next_question)
            elif isinstance(question_context, AskForRepeat):
                self.question.set(question=question_context.current_question)
                self.question.repeat_question(True)
            elif isinstance(question_context, Confirmation):
                confirmation_result = response_handler.confirming_answer()
                if confirmation_result is True:
                    self.question.set(question=question_context.next_question)
                    tts.say(question_context.intermediate_text)
                elif confirmation_result is False:
                    self.question.set(
                        question=question_context.current_question)

            if isinstance(self.question.question, EndOfConversation):
                debug("End of conversation")
                if self.question.question.text != "":
                    tts.say(self.question.question.text)
                end_of_conversation = True

        return True
Пример #7
0
 def execute(self):
     now = datetime.datetime.now()
     tts.say(_("Today is %s") % now.strftime("%A %d %b"))
Пример #8
0
 def start(self, conversation):
     debug("Starting conversation: " + str(conversation))
     self.conversation = conversation
     if hasattr(self.conversation, 'get_intro_text'):
         tts.say(self.conversation.get_intro_text())
     return self.start_conversation()