def initialize(self):
     self.tts = TTS()
     self.ui = UI_Control()
     self.conversation = Conversation(
         username='******',
         password='******',
         workspace_id='b291e39c-254a-46f5-80d9-b3f63fa0c58f')
Exemplo n.º 2
0
 def initialize(self):
     self.tts = TTS()
     self.ui = UI_Control()
     self.conversation = Conversation(
         username='******',
         password='******',
         workspace_id='3796d990-daf5-4dc7-b30b-a06e98f423a8')
Exemplo n.º 3
0
def get_conversation(df):
    messages = []
    for index, (date_time, sender, text) in df.iterrows():
        m = Message.from_args(date_time, sender, text)
        if '<Media omitted>' in text:
            m.set_media()
        messages.append(m)
    return Conversation(messages)
Exemplo n.º 4
0
    def initState(self):
        rospy.loginfo("init_state")
        self.ui.sendRobotMsg("대기상태 ... 사용자 감지 중입니다.")
        self.conversation = Conversation()
        self.userDetector.checkDetection()
        rospy.loginfo("user detected")

        self.ui.sendRobotMsg("사용자가 감지 되었습니다. 저와 이야기 하고 싶으면 안녕이라고 말씀해주세요.")
        self.tts.speak("사용자가 감지 되었습니다. 저와 이야기 하고 싶으면 안녕이라고 말씀해주세요.")
Exemplo n.º 5
0
class Dialogue:
    def __init__(self):
        pass

    def initialize(self):
        self.tts = TTS()
        self.ui = UI_Control()
        self.conversation = Conversation(
            username='******',
            password='******',
            workspace_id='3796d990-daf5-4dc7-b30b-a06e98f423a8')

    def main(self):
        self.handleInit()

        finished = False
        while finished is not True:
            response = self.getConversationResult()
            response_formatted = json.dumps(response,
                                            indent=2,
                                            ensure_ascii=False)
            rospy.loginfo(response_formatted.encode('utf8'))
            self.handleAibrilResponse(response)
            self.checkShutdown(response)
            if self.checkFinishFlag(response):
                self.tts.speak(("현재 대화 세션을 종료 하고, 초기 상태로 돌아갑니다."))
                self.handleInit()

    def checkFinishFlag(self, response):
        try:
            finish_flag = response['output']['finish_flag']
            if finish_flag is not None and finish_flag == "true": return True
        except KeyError as e:
            return False

    def handleInit(self):
        self.initialize()

        sentence = "안녕하세요. 만나서 반갑습니다. 저와 이야기 하고 싶으면 안녕 이라고 말씀해 주세요."
        self.ui.sendRobotMsg(unicode(sentence, 'utf-8'))
        self.tts.speak(sentence)

    def handleAibrilResponse(self, response):
        self.ui.sendAibrilMsg(response)
        self.tts.speak(response['output']['text'][0])

    def getConversationResult(self):
        def mic_callback():

            self.ui.sendUserInputWating()

        #
        # speech callback function
        #
        def speech_callback(speech_result):
            # print('Confidence: {}'.format(speech_result.confidence))
            # print('Transcript: {}'.format(speech_result.transcript))
            # print "is_final : ", speech_result.isFinal
            self.ui.sendUserMsg(speech_result)
            print ""

            #self.ui.sendUserMsg(speech_result.transcript)

        speech_result = stt_google.recognize(mic_callback=mic_callback,
                                             sentence_callback=speech_callback)
        self.ui.sendUserMsg(speech_result)

        response = self.conversation.getResponse(speech_result)
        response_formatted = json.dumps(response, indent=2, ensure_ascii=False)
        rospy.loginfo(response_formatted.encode('utf8'))

        #import  aibril_response
        #response = aibril_response.AibrilResponse.newInstance(response)
        return response

    def checkShutdown(self, response):
        entities = response['entities']
        for entity in entities:
            if entity['entity'] == "shutdown":
                sys.exit(1)
class AirportConcierge:
    def __init__(self):
        pass

    def initialize(self):
        self.tts = TTS()
        self.ui = UI_Control()
        self.conversation = Conversation(
            username='******',
            password='******',
            workspace_id='b291e39c-254a-46f5-80d9-b3f63fa0c58f')

    def main(self):
        self.handleInit()

        finished = False
        while finished is not True:
            response = self.getConversationResult()
            response_formatted = json.dumps(response,
                                            indent=2,
                                            ensure_ascii=False)
            rospy.loginfo(response_formatted.encode('utf8'))
            self.checkShutdown(response)
            self.handleAibrilResponse(response)

    def handleInit(self):
        self.initialize()

        sentence = "안녕하세요. 만나서 반갑습니다. 저와 이야기 하고 싶으면 안녕 이라고 말씀해 주세요."
        self.ui.sendRobotMsg(unicode(sentence, 'utf-8'))
        self.tts.speak(sentence)

    def handleAibrilResponse(self, response):
        self.ui.sendAibrilMsg(response)
        text = None
        for text in response['output']['text']:
            self.tts.speak(text)

    def getConversationResult(self):
        def mic_callback():

            self.ui.sendUserInputWating()

        #
        # speech callback function
        #
        def speech_callback(speech_result):
            # print('Confidence: {}'.format(speech_result.confidence))
            # print('Transcript: {}'.format(speech_result.transcript))
            # print "is_final : ", speech_result.isFinal
            self.ui.sendUserMsg(speech_result)
            print ""

            #self.ui.sendUserMsg(speech_result.transcript)

        speech_result = stt_google.recognize(mic_callback=mic_callback,
                                             sentence_callback=speech_callback)
        self.ui.sendUserMsg(speech_result)

        response = self.conversation.getResponse(speech_result)
        response_formatted = json.dumps(response, indent=2, ensure_ascii=False)
        rospy.loginfo(response_formatted.encode('utf8'))

        #import  aibril_response
        #response = aibril_response.AibrilResponse.newInstance(response)
        return response

    def checkShutdown(self, response):
        entities = response['entities']
        for entity in entities:
            if entity['entity'] == "shutdown":
                self.tts.speak('프로그램을 종료 합니다.')
                sys.exit(1)
            tts.speak("구글 음성인식기 오류 입니다. 다시 말씀해 주세요.")
            recogTrial = recogTrial + 1

    rospy.loginfo("sentence : ---->" + str(result.sentence) + ", flag : " +
                  str(result.success_flag))
    return result


def getConversationResult(tts, stt, conversation):
    sr_result = recogSpeech(tts, stt)
    conv_result = conversation.getResponse(sr_result.sentence)
    response_sentences = conv_result['output']['text']
    for sentence in response_sentences:
        tts.speak(sentence)
    return conv_result


if __name__ == "__main__":
    rospy.init_node("conversation_test", anonymous=True)
    conversation = Conversation()
    stt = SpeechRecognizer()
    tts = TTS()
    finish_flag = False

    tts.speak("안녕이라고 말씀해 주세요")
    while finish_flag is not True:
        response = getConversationResult(tts, stt, conversation)
        response_formatted = json.dumps(response, indent=2, ensure_ascii=False)
        print response_formatted

    rospy.spin()