Exemplo n.º 1
0
    def run(self):
        """ run ros node """
        # initialize ros node
        rospy.init_node('ChatTRCP')
        rospy.loginfo("start DoCoMo Chat TRCP node")
        """ for ROSpeexInterface """
        self.rospeex = ROSpeexInterface()
        self.rospeex.init()
        self.rospeex.register_sr_response(self.sr_response)
        """日本語(英語もある)でNICT(Googleもある)"""
        """launchファイ決めてもいいけど、動的に変更する?"""
        """とりあえず、現状は決め打ち"""
        self.lang = 'ja'
        #        self.input_engine = 'nict'
        self.input_engine = 'google'
        self.rospeex.set_spi_config(language='ja', engine='google')
        #        self.rospeex.set_spi_config(language=self.lang, engine=self.input_engine)
        """ 発話理解APIの準備 """
        self.req = DoCoMoUnderstandingReq()
        self.req.projectKey = 'OSU'
        self.req.appName = ''
        self.req.appKey = 'hoge_app01'
        self.req.clientVer = '1.0.0'
        self.req.dialogMode = 'off'
        self.req.language = 'ja'
        self.req.userId = '12 123456 123456 0'
        self.req.lat = '139.766084'
        self.req.lon = '35.681382'
        """ 雑談対話APIの準備 """
        self.req_chat = DoCoMoChatReq()
        self.req_chat.utt = ""

        self.req_chat.context = _chat_["context"]
        self.req_chat.nickname = _chat_["nickname"]
        self.req_chat.nickname_y = _chat_["nickname_y"]
        self.req_chat.sex = _chat_["sex"]
        self.req_chat.bloodtype = _chat_["bloodtype"]
        self.req_chat.birthdateY = _chat_["birthdateY"]
        self.req_chat.birthdateM = _chat_["birthdateM"]
        self.req_chat.birthdateD = _chat_["birthdateD"]
        self.req_chat.age = _chat_["age"]
        self.req_chat.constellations = _chat_["constellations"]
        self.req_chat.place = _chat_["place"]
        self.req_chat.mode = _chat_["mode"]
        self.req_chat.t = _chat_["t"]

        rospy.wait_for_service('docomo_sentenceunderstanding')
        self.understanding = rospy.ServiceProxy('docomo_sentenceunderstanding',
                                                DoCoMoUnderstanding)

        rospy.wait_for_service('docomo_qa')
        self.qa = rospy.ServiceProxy('docomo_qa', DoCoMoQa)

        rospy.wait_for_service('docomo_chat')
        self.chat = rospy.ServiceProxy('docomo_chat', DoCoMoChat)

        self.resp_understanding = DoCoMoUnderstandingRes()

        self.nowmode = "CHAT"
        rospy.spin()
Exemplo n.º 2
0
class talk_node(object):

    def __init__(self):

        self._interface = ROSpeexInterface()

    def sr_response(self, message):

        run = re.compile('(?P<run>走行)').search(message)
        start = re.compile('(?P<start>開始)').search(message)

	print 'you said : %s' %message

        if run is not None and start is not None:
	    text = u'ナビゲーションを開始します。'
	    robot_msg = 'start'

            rospy.loginfo(robot_msg)
            syscommand_pub.publish(robot_msg)


            print 'rospeex reply : %s' %text
            self._interface.say(text, 'ja', 'nict')

    def run(self):

        self._interface.init()
        self._interface.register_sr_response(self.sr_response)
        self._interface.set_spi_config(language='ja',engine='nict')
        rospy.spin()
Exemplo n.º 3
0
def main():
    rospy.init_node('demo')
    interface = ROSpeexInterface()
    interface.init()
    #    interface.set_sr_response()
    interface.register_sr_response(sr_response)
    interface.set_spi_config(language='ja', engine='nict')
    rospy.spin()
Exemplo n.º 4
0
def main():
    rospy.init_node('demo')
    interface = ROSpeexInterface()
    interface.init()
#    interface.set_sr_response()
    interface.register_sr_response( sr_response )
    interface.set_spi_config(language='ja', engine='nict')
    rospy.spin()
Exemplo n.º 5
0
class recognition(object):
    def __init__(self):
        self._interface = ROSpeexInterface()

    def sr_response(self, message):
        #文字列検索
        #止まる
        stop = re.compile('(?P<stop>止ま|ストップ)').search(message)
        #前に関するもの
        front = re.compile('(?P<front>前|進め)').search(message)
        #後ろに関するもの
        back = re.compile('(?P<back>後|下が|バック)').search(message)
        #右に関するもの
        right = re.compile('(?P<right>右)').search(message)
        #左に関するもの
        left = re.compile('(?P<left>左)').search(message)
        #認識した音声を出力
        print 'rospeex replay : %s' % message

        #検索した文字列に対して以下の数字を配信する
        #検索した文字列が何も一致しなかったら配信しない。
        if stop is not None:
            pub.publish(0)
        elif front is not None:
            pub.publish(1)
        elif back is not None:
            pub.publish(2)
        elif right is not None:
            pub.publish(3)
        elif left is not None:
            pub.publish(4)
        sleep(2)

    def run(self):
        """ run ros node """
        #初期化
        rospy.init_node('speech_recognition')
        self._interface.init()
        #音声認識エンジンの設定(言語,エンジン)
        self._interface.set_spi_config(language='ja', engine='nict')
        #音声認識結果取得用コールバック関数
        self._interface.register_sr_response(self.sr_response)
        rospy.spin()

if __name__ == "__main__":

    _pattern_rule = re.compile(
        '.*(robot)*.*(back|come|start|straight|right|left|stop|wait)')

    _operation_count = 0
    _turn_action = 0
    _started = False
    _force_stop = False
    _force_stop = False
    _during_right = False
    _during_left = False
    rospy.init_node('rospeex_turtle')
    rospeex = ROSpeexInterface()
    rospeex.init()
    rospeex.register_sr_response(sr_response)
    rospeex.set_spi_config(language='en', engine='nict')
    #rospeex.set_spi_config(language='en',engine='google')
    turtle_pub = rospy.Publisher('cmd_vel_mux/input/teleop', Twist)
    rospy.Timer(rospy.Duration(0, 100000000), timer_callback)

    try:
        rospy.spin()
    except:
        print e
    finally:
        twist = Twist()
        twist.linear.x = 0
        twist.linear.y = 0
Exemplo n.º 7
0
class ChatTRCP(object):
    """ ChatTRCP class """
    def __init__(self):
        """ Initializer """

    def run(self):
        """ run ros node """
        # initialize ros node
        rospy.init_node('ChatTRCP')
        rospy.loginfo("start DoCoMo Chat TRCP node")
        """ for ROSpeexInterface """
        self.rospeex = ROSpeexInterface()
        self.rospeex.init()
        self.rospeex.register_sr_response(self.sr_response)
        """日本語(英語もある)でNICT(Googleもある)"""
        """launchファイ決めてもいいけど、動的に変更する?"""
        """とりあえず、現状は決め打ち"""
        self.lang = 'ja'
        #        self.input_engine = 'nict'
        self.input_engine = 'google'
        self.rospeex.set_spi_config(language='ja', engine='google')
        #        self.rospeex.set_spi_config(language=self.lang, engine=self.input_engine)
        """ 発話理解APIの準備 """
        self.req = DoCoMoUnderstandingReq()
        self.req.projectKey = 'OSU'
        self.req.appName = ''
        self.req.appKey = 'hoge_app01'
        self.req.clientVer = '1.0.0'
        self.req.dialogMode = 'off'
        self.req.language = 'ja'
        self.req.userId = '12 123456 123456 0'
        self.req.lat = '139.766084'
        self.req.lon = '35.681382'
        """ 雑談対話APIの準備 """
        self.req_chat = DoCoMoChatReq()
        self.req_chat.utt = ""

        self.req_chat.context = _chat_["context"]
        self.req_chat.nickname = _chat_["nickname"]
        self.req_chat.nickname_y = _chat_["nickname_y"]
        self.req_chat.sex = _chat_["sex"]
        self.req_chat.bloodtype = _chat_["bloodtype"]
        self.req_chat.birthdateY = _chat_["birthdateY"]
        self.req_chat.birthdateM = _chat_["birthdateM"]
        self.req_chat.birthdateD = _chat_["birthdateD"]
        self.req_chat.age = _chat_["age"]
        self.req_chat.constellations = _chat_["constellations"]
        self.req_chat.place = _chat_["place"]
        self.req_chat.mode = _chat_["mode"]
        self.req_chat.t = _chat_["t"]

        rospy.wait_for_service('docomo_sentenceunderstanding')
        self.understanding = rospy.ServiceProxy('docomo_sentenceunderstanding',
                                                DoCoMoUnderstanding)

        rospy.wait_for_service('docomo_qa')
        self.qa = rospy.ServiceProxy('docomo_qa', DoCoMoQa)

        rospy.wait_for_service('docomo_chat')
        self.chat = rospy.ServiceProxy('docomo_chat', DoCoMoChat)

        self.resp_understanding = DoCoMoUnderstandingRes()

        self.nowmode = "CHAT"
        rospy.spin()

    """ DoCoMo 雑談対話の実行 """

    def execChat(self, message):
        # Rospeexを使うと、文字列の最後に「。」が付くので削除する
        src = message
        dst = src.replace('。', '')
        self.req_chat.utt = dst

        self.res_chat = self.chat(self.req_chat)
        rospy.loginfo("TRCP Chat response:%s", self.res_chat.response)
        self.rospeex.say(self.res_chat.response.yomi, 'ja', 'nict')

        return True

    """ DoCoMo 知識検索の実行 """

    def execQA(self, message):
        rospy.loginfo("TRCP:Q&A")
        self.req_qa = DoCoMoQaReq()
        self.req_qa.text = message
        res_qa = self.qa(self.req_qa)
        rospy.loginfo("TRCP Q&A response:%s", res_qa.response.code)
        self.rospeex.say(res_qa.response.textForSpeech, 'ja', 'nict')

        return True

    def sr_response(self, message):
        rospy.loginfo("sr_responsee:%s", message)
        #message が特定のキーワードであれば、それに対応した処理を行う
        """ 時間 ->現在時刻を答える"""
        time = re.compile('(?P<time>何時)').search(message)
        if time is not None:
            rospy.loginfo("What Time is it now? :%s", message)
            d = datetime.datetime.today()
            text = u'%d時%d分です。' % (d.hour, d.minute)
            # rospeex reply
            self.rospeex.say(text, 'ja', 'nict')
            return True
        """ 自己紹介 ->挨拶する"""
        hello = re.compile('(?P<introduce>)自己紹介').search(message)
        if hello is not None:
            rospy.loginfo("Self introduce :%s", message)
            text = "皆さんこんにちわ。私の名前はイレイサーです。僕は家庭でみんなの手伝いをするために作られたホームサービスロボットなんだ。"
            # rospeex reply
            self.rospeex.say(text, 'ja', 'nict')
            return True

        # 特定のキーワード処理はここまで

        try:
            """ もし現在の会話モードが「しりとり」なら
                文章理解APIをスキップする
            """
            if self.nowmode == "CHAIN":
                self.resp_understanding.success = True
                self.resp_understanding.response.commandId = "BC00101"
                self.resp_understanding.response.utteranceText = message
            else:
                self.req.utteranceText = message
                self.resp_understanding = self.understanding(self.req)

            if self.resp_understanding.success:
                commandId = self.resp_understanding.response.commandId
                rospy.loginfo("<<< %s", commandId)
                if commandId == "BC00101":
                    rospy.loginfo("BBBB")
                    """雑談"""
                    rospy.loginfo("TRCP:Chat")

                    # Rospeexを使うと、文字列の最後に「。」が付くので削除する
                    src = self.resp_understanding.response.utteranceText
                    dst = src.replace('。', '')
                    self.req_chat.utt = dst

                    self.res_chat = self.chat(self.req_chat)
                    rospy.loginfo("TRCP Chat response:%s",
                                  self.res_chat.response)
                    """雑談対話からのレスポンスを設定する"""
                    self.req_chat.mode = self.res_chat.response.mode.encode(
                        'utf-8')
                    self.req_chat.context = self.res_chat.response.context.encode(
                        'utf-8')

                    if self.nowmode == "CHAIN":
                        if self.res_chat.response.mode == "srtr":
                            self.nowmode = "CHAIN"
                            self.rospeex.say(self.res_chat.response.utt, 'ja',
                                             'nict')
                        else:
                            self.nowmode = "CHAT"
                            self.rospeex.say(self.res_chat.response.utt, 'ja',
                                             'nict')
                    elif self.nowmode == "CHAT":
                        if self.res_chat.response.mode == "srtr":
                            self.nowmode = "CHAIN"
                            self.rospeex.say(self.res_chat.response.utt, 'ja',
                                             'nict')
                        else:
                            self.nowmode = "CHAT"
                            self.rospeex.say(self.res_chat.response.yomi, 'ja',
                                             'nict')

                elif commandId == "BK00101":
                    """知識検索"""
                    rospy.loginfo("TRCP:Q&A")
                    self.req_qa = DoCoMoQaReq()
                    self.req_qa.text = self.resp_understanding.response.utteranceText
                    print self.resp_understanding.response.utteranceText
                    res_qa = self.qa(self.req_qa)
                    rospy.loginfo("TRCP Q&A response:%s", res_qa.response.code)
                    self.rospeex.say(res_qa.response.textForSpeech, 'ja',
                                     'nict')
                    """
                    質問回答のレスポンスコードは、下記のいずれかを返却。
                    S020000: 内部のDBからリストアップした回答
                    S020001: 知識Q&A APIが計算した回答
                    S020010: 外部サイトから抽出した回答候補
                    S020011: 外部サイトへのリンクを回答
                    E010000: 回答不能(パラメータ不備)
                    E020000: 回答不能(結果0件)
                    E099999: 回答不能(処理エラー)
                    ※Sで始まる場合は正常回答、
                    Eで始まる場合は回答が得られていないことを示す。
                    """
                    if res_qa.success:
                        print res_qa.response.textForDisplay
                        rospy.loginfo("TRCP:%s", res_qa.response.textForSpeech)
                        # for answer in res_qa.response.answer:
                        #     print answer.rank
                        #     print answer.answerText
                        #     print answer.linkText
                        #     print answer.linkUrl
                        if res_qa.response.code == 'S020000':
                            pass
                        elif res_qa.response.code == 'S020001':
                            pass
                        elif res_qa.response.code == 'S020010':
                            pass
                        elif res_qa.response.code == 'S020011':
                            pass
                        elif res_qa.response.code == 'E010000':
                            pass
                        elif res_qa.response.code == 'E020000':
                            pass
                        elif res_qa.response.code == 'E099999':
                            pass
                        else:
                            pass
                    else:
                        pass

                elif commandId == "BT00101":
                    """乗換案内"""
                    rospy.loginfo(":Transfer")
                    self.execQA(message)
                elif commandId == "BT00201":
                    """地図"""
                    rospy.loginfo(":Map")
                    self.execQA(message)

                elif commandId == "BT00301":
                    """天気"""
                    rospy.loginfo(":Weather")
                    """お天気検索"""
                    """http://weather.livedoor.com/weather_hacks/webservice"""
                    #                    self.execQA(message)
                    self.execChat(message)

                elif commandId == "BT00401":
                    """グルメ検索"""
                    rospy.loginfo(":Restaurant")
                    """ グルなびWebサービス"""
                    """http://api.gnavi.co.jp/api/"""
                    self.execQA(message)

                elif commandId == "BT00501":
                    """ブラウザ"""
                    rospy.loginfo(":Webpage")
                    self.execQA(message)
                elif commandId == "BT00601":
                    """観光案内"""
                    rospy.loginfo(":Sightseeing")
                    self.execQA(message)
                elif commandId == "BT00701":
                    """カメラ"""
                    rospy.loginfo(":Camera")
                    self.execQA(message)
                elif commandId == "BT00801":
                    """ギャラリー"""
                    rospy.loginfo(":Gallery")
                    self.execQA(message)
                elif commandId == "BT00901":
                    """通信"""
                    rospy.loginfo(":Coomunincation")
                    self.execQA(message)
                elif commandId == "BT01001":
                    """メール"""
                    rospy.loginfo(":Mail")
                    self.execQA(message)
                elif commandId == "BT01101":
                    """メモ登録"""
                    rospy.loginfo(":Memo input")
                    self.execQA(message)
                elif commandId == "BT01102":
                    """メモ参照"""
                    rospy.loginfo(":Memo output")
                    self.execQA(message)
                elif commandId == "BT01201":
                    """アラーム"""
                    rospy.loginfo(":Alarm")
                    self.execQA(message)
                elif commandId == "BT01301":
                    """スケジュール登録"""
                    rospy.loginfo(":Schedule input")
                    self.execQA(message)

                elif commandId == "BT01302":
                    """スケジュール参照"""
                    rospy.loginfo(":Schedule input")
                    self.execQA(message)
                elif commandId == "BT01501":
                    """端末設定"""
                    rospy.loginfo(":Setting")
                    self.execQA(message)
                elif commandId == "BT01601":
                    """SNS投稿"""
                    rospy.loginfo(":SNS")
                    self.execQA(message)
                elif commandId == "BT90101":
                    """キャンセル"""
                    rospy.loginfo(":Cancel")
                    self.execQA(message)
                elif commandId == "BM00101":
                    """地図乗換"""
                    rospy.loginfo(":Map transfer")
                    self.execQA(message)
                elif commandId == "BM00201":
                    """通話メール"""
                    rospy.loginfo(":Short mail")
                    self.execQA(message)

                else:
                    """発話理解APIで判定不能"""
                    """Undeterminable"""
                    rospy.loginfo("Undeterminable:%s",
                                  self.resp_understanding.response.commandId)
                    self.rospeex.say("ごめんなさい、良く聞き取れませんでした。", 'ja', 'nict')

            else:
                """発話理解APIがエラーのとき"""
                rospy.loginfo("DoCoMo 発話理解API failed")
                pass
        except:
            """対話プログラムのどこかでエラーのとき"""
            rospy.loginfo("error")
            pass

        return True
Exemplo n.º 8
0
    def __init__(self):

        self._interface = ROSpeexInterface()
Exemplo n.º 9
0
    def run(self):
        """ run ros node """
        # initialize ros node
        rospy.init_node('ChatTRCP')
        rospy.loginfo("start DoCoMo Chat TRCP node")
        
        """ for ROSpeexInterface """
        self.rospeex = ROSpeexInterface()
        self.rospeex.init()
        self.rospeex.register_sr_response( self.sr_response )

        """日本語(英語もある)でNICT(Googleもある)"""
        """launchファイ決めてもいいけど、動的に変更する?"""
        """とりあえず、現状は決め打ち"""
        self.lang = 'ja'
#        self.input_engine = 'nict'        
        self.input_engine = 'google'        
        self.rospeex.set_spi_config(language='ja',engine='google')
#        self.rospeex.set_spi_config(language=self.lang, engine=self.input_engine)


        """ 発話理解APIの準備 """
        self.req = DoCoMoUnderstandingReq()
        self.req.projectKey = 'OSU'    
        self.req.appName = ''
        self.req.appKey = 'hoge_app01'
        self.req.clientVer = '1.0.0'
        self.req.dialogMode = 'off'
        self.req.language = 'ja'
        self.req.userId = '12 123456 123456 0'
        self.req.lat = '139.766084'
        self.req.lon = '35.681382'

        """ 雑談対話APIの準備 """
        self.req_chat = DoCoMoChatReq()
        self.req_chat.utt = ""

        self.req_chat.context = _chat_["context"]
        self.req_chat.nickname = _chat_["nickname"]
        self.req_chat.nickname_y = _chat_["nickname_y"]
        self.req_chat.sex = _chat_["sex"]
        self.req_chat.bloodtype = _chat_["bloodtype"]
        self.req_chat.birthdateY = _chat_["birthdateY"]
        self.req_chat.birthdateM = _chat_["birthdateM"]
        self.req_chat.birthdateD = _chat_["birthdateD"]
        self.req_chat.age = _chat_["age"]
        self.req_chat.constellations = _chat_["constellations"]
        self.req_chat.place = _chat_["place"]
        self.req_chat.mode = _chat_["mode"]
        self.req_chat.t = _chat_["t"]


        rospy.wait_for_service('docomo_sentenceunderstanding')
        self.understanding = rospy.ServiceProxy('docomo_sentenceunderstanding',DoCoMoUnderstanding)

        rospy.wait_for_service('docomo_qa')        
        self.qa = rospy.ServiceProxy('docomo_qa',DoCoMoQa)

        rospy.wait_for_service('docomo_chat')        
        self.chat = rospy.ServiceProxy('docomo_chat',DoCoMoChat)

        self.resp_understanding = DoCoMoUnderstandingRes()
        
        self.nowmode = "CHAT"
        rospy.spin()
Exemplo n.º 10
0
class ChatTRCP(object):
    """ ChatTRCP class """
    def __init__(self):
        """ Initializer """

    def run(self):
        """ run ros node """
        # initialize ros node
        rospy.init_node('ChatTRCP')
        rospy.loginfo("start DoCoMo Chat TRCP node")
        
        """ for ROSpeexInterface """
        self.rospeex = ROSpeexInterface()
        self.rospeex.init()
        self.rospeex.register_sr_response( self.sr_response )

        """日本語(英語もある)でNICT(Googleもある)"""
        """launchファイ決めてもいいけど、動的に変更する?"""
        """とりあえず、現状は決め打ち"""
        self.lang = 'ja'
#        self.input_engine = 'nict'        
        self.input_engine = 'google'        
        self.rospeex.set_spi_config(language='ja',engine='google')
#        self.rospeex.set_spi_config(language=self.lang, engine=self.input_engine)


        """ 発話理解APIの準備 """
        self.req = DoCoMoUnderstandingReq()
        self.req.projectKey = 'OSU'    
        self.req.appName = ''
        self.req.appKey = 'hoge_app01'
        self.req.clientVer = '1.0.0'
        self.req.dialogMode = 'off'
        self.req.language = 'ja'
        self.req.userId = '12 123456 123456 0'
        self.req.lat = '139.766084'
        self.req.lon = '35.681382'

        """ 雑談対話APIの準備 """
        self.req_chat = DoCoMoChatReq()
        self.req_chat.utt = ""

        self.req_chat.context = _chat_["context"]
        self.req_chat.nickname = _chat_["nickname"]
        self.req_chat.nickname_y = _chat_["nickname_y"]
        self.req_chat.sex = _chat_["sex"]
        self.req_chat.bloodtype = _chat_["bloodtype"]
        self.req_chat.birthdateY = _chat_["birthdateY"]
        self.req_chat.birthdateM = _chat_["birthdateM"]
        self.req_chat.birthdateD = _chat_["birthdateD"]
        self.req_chat.age = _chat_["age"]
        self.req_chat.constellations = _chat_["constellations"]
        self.req_chat.place = _chat_["place"]
        self.req_chat.mode = _chat_["mode"]
        self.req_chat.t = _chat_["t"]


        rospy.wait_for_service('docomo_sentenceunderstanding')
        self.understanding = rospy.ServiceProxy('docomo_sentenceunderstanding',DoCoMoUnderstanding)

        rospy.wait_for_service('docomo_qa')        
        self.qa = rospy.ServiceProxy('docomo_qa',DoCoMoQa)

        rospy.wait_for_service('docomo_chat')        
        self.chat = rospy.ServiceProxy('docomo_chat',DoCoMoChat)

        self.resp_understanding = DoCoMoUnderstandingRes()
        
        self.nowmode = "CHAT"
        rospy.spin()




    """ DoCoMo 雑談対話の実行 """
    def execChat(self, message):
        # Rospeexを使うと、文字列の最後に「。」が付くので削除する
        src = message
        dst=src.replace('。', '')
        self.req_chat.utt = dst

        self.res_chat = self.chat(self.req_chat)
        rospy.loginfo("TRCP Chat response:%s",self.res_chat.response)
        self.rospeex.say(self.res_chat.response.yomi , 'ja', 'nict')

        return True

    """ DoCoMo 知識検索の実行 """
    def execQA(self, message):
        rospy.loginfo("TRCP:Q&A")
        self.req_qa = DoCoMoQaReq()
        self.req_qa.text = message
        res_qa = self.qa(self.req_qa)
        rospy.loginfo("TRCP Q&A response:%s",res_qa.response.code)
        self.rospeex.say(res_qa.response.textForSpeech , 'ja', 'nict')

        return True

    def sr_response(self, message):
        rospy.loginfo("sr_responsee:%s", message)
        #message が特定のキーワードであれば、それに対応した処理を行う

        """ 時間 ->現在時刻を答える"""
        time = re.compile('(?P<time>何時)').search(message)
        if time is not None:
            rospy.loginfo("What Time is it now? :%s", message)        
            d = datetime.datetime.today()
            text = u'%d時%d分です。'%(d.hour, d.minute)
            # rospeex reply
            self.rospeex.say(text, 'ja', 'nict')
            return True

        """ 自己紹介 ->挨拶する"""
        hello = re.compile('(?P<introduce>)自己紹介').search(message)
        if hello is not None:
            rospy.loginfo("Self introduce :%s", message)        
            text = "皆さんこんにちわ。私の名前はイレイサーです。僕は家庭でみんなの手伝いをするために作られたホームサービスロボットなんだ。"
            # rospeex reply
            self.rospeex.say(text, 'ja', 'nict')
            return True

        # 特定のキーワード処理はここまで
            
        try:
            """ もし現在の会話モードが「しりとり」なら
                文章理解APIをスキップする
            """
            if self.nowmode == "CHAIN":
                self.resp_understanding.success = True
                self.resp_understanding.response.commandId = "BC00101"
                self.resp_understanding.response.utteranceText = message
            else:
                self.req.utteranceText = message
                self.resp_understanding = self.understanding(self.req)


            if  self.resp_understanding.success:
                commandId = self.resp_understanding.response.commandId
                rospy.loginfo("<<< %s", commandId)
                if commandId == "BC00101":
                    rospy.loginfo("BBBB")
                    """雑談"""
                    rospy.loginfo("TRCP:Chat")

                    
                    # Rospeexを使うと、文字列の最後に「。」が付くので削除する
                    src = self.resp_understanding.response.utteranceText
                    dst=src.replace('。', '')
                    self.req_chat.utt = dst

                    self.res_chat = self.chat(self.req_chat)
                    rospy.loginfo("TRCP Chat response:%s",self.res_chat.response)

                    """雑談対話からのレスポンスを設定する"""
                    self.req_chat.mode = self.res_chat.response.mode.encode('utf-8')
                    self.req_chat.context = self.res_chat.response.context.encode('utf-8')

                    if self.nowmode == "CHAIN":
                        if self.res_chat.response.mode == "srtr":
                            self.nowmode = "CHAIN"                    
                            self.rospeex.say(self.res_chat.response.utt , 'ja', 'nict')
                        else:
                            self.nowmode = "CHAT"
                            self.rospeex.say(self.res_chat.response.utt , 'ja', 'nict')
                    elif self.nowmode == "CHAT":                       
                        if self.res_chat.response.mode == "srtr":
                            self.nowmode = "CHAIN"                    
                            self.rospeex.say(self.res_chat.response.utt , 'ja', 'nict')
                        else:
                            self.nowmode = "CHAT"
                            self.rospeex.say(self.res_chat.response.yomi , 'ja', 'nict')


                elif commandId  == "BK00101":
                    """知識検索"""
                    rospy.loginfo("TRCP:Q&A")
                    self.req_qa = DoCoMoQaReq()
                    self.req_qa.text = self.resp_understanding.response.utteranceText
                    print self.resp_understanding.response.utteranceText
                    res_qa = self.qa(self.req_qa)
                    rospy.loginfo("TRCP Q&A response:%s",res_qa.response.code)
                    self.rospeex.say(res_qa.response.textForSpeech , 'ja', 'nict')

                    """
                    質問回答のレスポンスコードは、下記のいずれかを返却。
                    S020000: 内部のDBからリストアップした回答
                    S020001: 知識Q&A APIが計算した回答
                    S020010: 外部サイトから抽出した回答候補
                    S020011: 外部サイトへのリンクを回答
                    E010000: 回答不能(パラメータ不備)
                    E020000: 回答不能(結果0件)
                    E099999: 回答不能(処理エラー)
                    ※Sで始まる場合は正常回答、
                    Eで始まる場合は回答が得られていないことを示す。
                    """
                    if res_qa.success:
                        print res_qa.response.textForDisplay
                        rospy.loginfo("TRCP:%s",res_qa.response.textForSpeech)
                        # for answer in res_qa.response.answer:
                        #     print answer.rank
                        #     print answer.answerText
                        #     print answer.linkText
                        #     print answer.linkUrl
                        if res_qa.response.code == 'S020000':
                            pass
                        elif res_qa.response.code == 'S020001':
                            pass
                        elif res_qa.response.code == 'S020010':
                            pass
                        elif res_qa.response.code == 'S020011':
                            pass                            
                        elif res_qa.response.code == 'E010000':
                            pass
                        elif res_qa.response.code == 'E020000':
                            pass
                        elif res_qa.response.code == 'E099999':
                            pass
                        else:
                            pass
                    else:
                        pass


                elif commandId  == "BT00101":
                    """乗換案内"""
                    rospy.loginfo(":Transfer")
                    self.execQA(message)                                        
                elif commandId  == "BT00201":
                    """地図"""
                    rospy.loginfo(":Map")                    
                    self.execQA(message)                    

                elif commandId == "BT00301":
                    """天気"""
                    rospy.loginfo(":Weather")                    
                    """お天気検索"""
                    """http://weather.livedoor.com/weather_hacks/webservice"""
#                    self.execQA(message)
                    self.execChat(message)                                        

                elif commandId == "BT00401":
                    """グルメ検索"""
                    rospy.loginfo(":Restaurant")
                    """ グルなびWebサービス"""
                    """http://api.gnavi.co.jp/api/"""
                    self.execQA(message)                    

                    
                elif commandId == "BT00501":
                    """ブラウザ"""
                    rospy.loginfo(":Webpage")
                    self.execQA(message)                                                            
                elif commandId == "BT00601":
                    """観光案内"""
                    rospy.loginfo(":Sightseeing")
                    self.execQA(message)                                                            
                elif commandId == "BT00701":
                    """カメラ"""
                    rospy.loginfo(":Camera")
                    self.execQA(message)                                                            
                elif commandId == "BT00801":
                    """ギャラリー"""
                    rospy.loginfo(":Gallery")
                    self.execQA(message)                                                            
                elif commandId == "BT00901":
                    """通信"""
                    rospy.loginfo(":Coomunincation")
                    self.execQA(message)                                                            
                elif commandId == "BT01001":
                    """メール"""
                    rospy.loginfo(":Mail")
                    self.execQA(message)                                                            
                elif commandId == "BT01101":
                    """メモ登録"""
                    rospy.loginfo(":Memo input")
                    self.execQA(message)                                                            
                elif commandId == "BT01102":
                    """メモ参照"""
                    rospy.loginfo(":Memo output")
                    self.execQA(message)                                                            
                elif commandId == "BT01201":
                    """アラーム"""
                    rospy.loginfo(":Alarm")
                    self.execQA(message)                                                            
                elif commandId == "BT01301":
                    """スケジュール登録"""
                    rospy.loginfo(":Schedule input")
                    self.execQA(message)
                    
                elif commandId == "BT01302":
                    """スケジュール参照"""
                    rospy.loginfo(":Schedule input")
                    self.execQA(message)                                                            
                elif commandId == "BT01501":
                    """端末設定"""
                    rospy.loginfo(":Setting")
                    self.execQA(message)                                                            
                elif commandId == "BT01601":
                    """SNS投稿"""
                    rospy.loginfo(":SNS")
                    self.execQA(message)                                                            
                elif commandId == "BT90101":
                    """キャンセル"""
                    rospy.loginfo(":Cancel")
                    self.execQA(message)                                                            
                elif commandId == "BM00101":
                    """地図乗換"""
                    rospy.loginfo(":Map transfer")
                    self.execQA(message)                                                            
                elif commandId == "BM00201":
                    """通話メール"""
                    rospy.loginfo(":Short mail")
                    self.execQA(message)                                                            
                    
                else:
                    """発話理解APIで判定不能"""
                    """Undeterminable"""     
                    rospy.loginfo("Undeterminable:%s",self.resp_understanding.response.commandId)
                    self.rospeex.say("ごめんなさい、良く聞き取れませんでした。" , 'ja', 'nict')


            else:
                """発話理解APIがエラーのとき"""
                rospy.loginfo("DoCoMo 発話理解API failed")
                pass
        except:
            """対話プログラムのどこかでエラーのとき"""
            rospy.loginfo("error")
            pass

        return True
Exemplo n.º 11
0
        if operation == "come" or operation == "follow" or operation == "on" or operation == "one" or operation == "start":
	    pubvoice = rospy.Publisher('follow', String)
            pubvoice.publish(String("Follow"))            
	    print "Following. and published"
	    speak("WoofWoof")

        elif operation == "stop" or operation == "wait" or operation == "off" or operation == "two":
	    pubvoice = rospy.Publisher('follow', String)
            pubvoice.publish(String("Stop"))
            print "I stopped. and published"
	    speak("WoofWoof")

    elif message != "":
	#speak("What")
        print "What?"

if __name__=="__main__":

    _pattern_rule = re.compile( '.*(robot)*.*(back|come|stop|wait)')

    rospy.init_node('rospeex_turtle')
    rospeex = ROSpeexInterface()
    rospeex.init()
    rospeex.register_sr_response( sr_response )
    rospeex.set_spi_config(language='en',engine='nict')

    try:
        rospy.spin();
    except:
        print e
Exemplo n.º 12
0
class ChatTRCP(object):
    """ ChatTRCP class """
    def __init__(self):
        """ Initializer """

    def run(self):
        """ run ros node """
        # initialize ros node
        rospy.init_node('ChatTRCP')
        rospy.loginfo("start DoCoMo Chat TRCP node")
        """ for ROSpeexInterface """
        self.rospeex = ROSpeexInterface()
        self.rospeex.init()
        self.rospeex.register_sr_response(self.sr_response)
        self.rospeex.set_spi_config(language='ja', engine='nict')
        """日本語(英語もある)でNICT(Googleもある)"""
        """launchファイ決めてもいいけど、動的に変更する?"""
        """とりあえず、現状は決め打ち"""
        self.lang = 'ja'
        self.input_engine = 'nict'
        self.rospeex.set_spi_config(language='ja', engine='nict')
        """ for jsk voice understanding """
        rospy.Subscriber("/Tablet/voice", VoiceMessage, self.jsk_voice)
        """ 発話理解APIの準備 """
        self.req = DoCoMoUnderstandingReq()
        self.req.projectKey = 'OSU'
        self.req.appName = ''
        self.req.appKey = 'hoge_app01'
        self.req.clientVer = '1.0.0'
        self.req.dialogMode = 'off'
        self.req.language = 'ja'
        self.req.userId = '12 123456 123456 0'
        self.req.lat = '139.766084'
        self.req.lon = '35.681382'
        """ 雑談対話APIの準備 """
        self.req_chat = DoCoMoChatReq()
        self.req_chat.utt = ""

        self.req_chat.context = _chat_["context"]
        self.req_chat.nickname = _chat_["nickname"]
        self.req_chat.nickname_y = _chat_["nickname_y"]
        self.req_chat.sex = _chat_["sex"]
        self.req_chat.bloodtype = _chat_["bloodtype"]
        self.req_chat.birthdateY = _chat_["birthdateY"]
        self.req_chat.birthdateM = _chat_["birthdateM"]
        self.req_chat.birthdateD = _chat_["birthdateD"]
        self.req_chat.age = _chat_["age"]
        self.req_chat.constellations = _chat_["constellations"]
        self.req_chat.place = _chat_["place"]
        self.req_chat.mode = _chat_["mode"]
        self.req_chat.t = _chat_["t"]

        rospy.wait_for_service('docomo_sentenceunderstanding')
        self.understanding = rospy.ServiceProxy('docomo_sentenceunderstanding',
                                                DoCoMoUnderstanding)

        rospy.wait_for_service('docomo_qa')
        self.qa = rospy.ServiceProxy('docomo_qa', DoCoMoQa)

        rospy.wait_for_service('docomo_chat')
        self.chat = rospy.ServiceProxy('docomo_chat', DoCoMoChat)

        self.resp_understanding = DoCoMoUnderstandingRes()

        _nowmode = "CHAT"

        rospy.spin()

    def jsk_voice(self, data):
        #        print len(data.texts)
        #        for elem in data.texts:
        #            print elem
        rospy.loginfo("jsk_voice:%s", data.texts[0])
        self.chat(data.texts[0])

    def sr_response(self, message):
        # Rospeexを使うと、文字列の最後に「。」が付くので削除する
        src = message
        sr_dst = src.replace('。', '')
        rospy.loginfo("rospeex:%s", sr_dst)
        chat(sr_dst)

    def chat(self, message):
        rospy.loginfo("chat:%s", message)

        #message が特定のキーワードであれば、それに対応した処理を行う
        """ 時間 ->現在時刻を答える"""
        time = re.compile('(?P<time>何時)').search(message)
        if time is not None:
            rospy.loginfo("What Time is it now? :%s", message)
            d = datetime.datetime.today()
            text = u'%d時%d分です。' % (d.hour, d.minute)
            # rospeex reply
            self.rospeex.say(text, 'ja', 'nict')
            return True

        # 特定のキーワード処理はここまで

        print _nowmode
        try:
            """ もし現在の会話モードが「しりとり」なら
                文章理解APIをスキップする

                それ以外なら、文章理解APIで文章を解析する
            """
            if _nowmode == "CHAIN":
                self.resp_understanding.success = True
                self.resp_understanding.response.commandId = "BC00101"
                self.resp_understanding.response.utteranceText = message
            else:
                self.req.utteranceText = message
                self.resp_understanding = self.understanding(self.req)

            if self.resp_understanding.success:
                commandId = self.resp_understanding.response.commandId
                rospy.loginfo("<<< %s", commandId)
                if commandId == "BC00101":
                    """雑談"""
                    rospy.loginfo("TRCP:Chat")
                    self.res_chat = self.chat(self.req_chat)
                    rospy.loginfo("TRCP Chat response:%s",
                                  self.res_chat.response)

                elif commandId == "BK00101":
                    """知識検索"""
                    rospy.loginfo("TRCP:Q&A")
                    self.req_qa = DoCoMoQaReq()
                    self.req_qa.text = self.resp_understanding.response.utteranceText
                    print self.resp_understanding.response.utteranceText
                    res_qa = self.qa(self.req_qa)
                    rospy.loginfo("TRCP Q&A response:%s", res_qa.response.code)
                    self.rospeex.say(res_qa.response.textForSpeech, 'ja',
                                     'nict')

            else:
                """発話理解APIがエラーのとき"""
                rospy.loginfo("DoCoMo 発話理解API failed")
                pass

        except:
            """対話プログラムのどこかでエラーのとき"""
            rospy.loginfo("error")
            pass

        return True
Exemplo n.º 13
0
    f.write(cbstr)
    f.close()
    sys.stdout.write('cbstr: ')
    print(cbstr)
    f = open(text_data, 'r')
    voice_data = f.read()
    voice_data = voice_data.decode('utf-8')
    sys.stdout.write('voice text:')
    print(voice_data)
    f.close()
    interface.say(voice_data, language=language, engine='nict')
    endflg = 1


rospy.init_node("hoge")
interface = ROSpeexInterface()
interface.init()

interface.register_sr_response(callback)
interface.register_ss_response(ss_callback)
#language = "en"
language = 'ja'
#voice_font = "nict(ja)"
text_data = 'recognized_text.txt'

interface.set_spi_config(language=language, engine='nict')

endflg = 0


def recognize_speak(filename):
Exemplo n.º 14
0
    def run(self):
        """ run ros node """
        # initialize ros node
        rospy.init_node('ChatTRCP')
        rospy.loginfo("start DoCoMo Chat TRCP node")





        """ for ROSpeexInterface """
        self.rospeex = ROSpeexInterface()
        self.rospeex.init()
        self.rospeex.register_sr_response( self.sr_response )
        self.rospeex.set_spi_config(language='ja', engine='nict')

        """日本語(英語もある)でNICT(Googleもある)"""
        """launchファイ決めてもいいけど、動的に変更する?"""
        """とりあえず、現状は決め打ち"""
        self.lang = 'ja'
        self.input_engine = 'nict'        
        self.rospeex.set_spi_config(language='ja',engine='nict')



        """ for jsk voice understanding """
        rospy.Subscriber("/Tablet/voice", VoiceMessage, self.jsk_voice)



        """ 発話理解APIの準備 """
        self.req = DoCoMoUnderstandingReq()

        self.req.projectKey = rospy.get_param("~req_projectKey", 'OSU')
        self.req.appName = rospy.get_param("~req_appName" ,'')
        self.req.appKey = rospy.get_param("~req_appKey" ,'hoge_app01')
        self.req.clientVer = rospy.get_param("~req_clientVer",  '1.0.0')
        self.req.dialogMode = rospy.get_param("~req_dialogMode",'off')
        self.req.language = rospy.get_param("~req_language", 'ja')
        self.req.userId = rospy.get_param("~req_userId", '12 123456 123456 0')
        self.req.lat = rospy.get_param("~req_lat" , '139.766084')
        self.req.lon = rospy.get_param("~req_lon" , '35.681382')


        """ 雑談対話APIの準備 """
        self.req_chat = DoCoMoChatReq()
        self.req_chat.utt = ""

        self.req_chat.context =  rospy.get_param("~context", "aaabbbccc111222333")
        self.req_chat.nickname = rospy.get_param("~nickname", "ひろゆき")
        self.req_chat.nickname_y = rospy.get_param("~nickname_y", "ヒロユキ")
        self.req_chat.sex = rospy.get_param("~sex", "男")
        self.req_chat.bloodtype = rospy.get_param("~bloodtype", "AB")
        self.req_chat.birthdateY = rospy.get_param("~birthdateY", "1960")
        self.req_chat.birthdateM = rospy.get_param("~birthdateM", "7")
        self.req_chat.birthdateD = rospy.get_param("~birthdateD", "11")
        self.req_chat.age = rospy.get_param("~age", "56")
        self.req_chat.constellations = rospy.get_param("~constellations", "蟹")
        self.req_chat.place = rospy.get_param("~place", "東京")
        self.req_chat.mode = rospy.get_param("~mode", "dialog")
        self.req_chat.t = rospy.get_param("~t", "20")


        """ サービスの起動 """
        rospy.wait_for_service('docomo_sentenceunderstanding')
        self.understanding = rospy.ServiceProxy('docomo_sentenceunderstanding',DoCoMoUnderstanding)

        rospy.wait_for_service('docomo_qa')        
        self.qa = rospy.ServiceProxy('docomo_qa',DoCoMoQa)

        rospy.wait_for_service('docomo_chat')        
        self.chat = rospy.ServiceProxy('docomo_chat',DoCoMoChat)

        self.resp_understanding = DoCoMoUnderstandingRes()
        
        self.nowmode = "CHAT"
        rospy.spin()
Exemplo n.º 15
0
class ChatTRCP(object):
    """ ChatTRCP class """
    def __init__(self):
        """ Initializer """

    def run(self):
        """ run ros node """
        # initialize ros node
        rospy.init_node('ChatTRCP')
        rospy.loginfo("start DoCoMo Chat TRCP node")





        """ for ROSpeexInterface """
        self.rospeex = ROSpeexInterface()
        self.rospeex.init()
        self.rospeex.register_sr_response( self.sr_response )
        self.rospeex.set_spi_config(language='ja', engine='nict')

        """日本語(英語もある)でNICT(Googleもある)"""
        """launchファイ決めてもいいけど、動的に変更する?"""
        """とりあえず、現状は決め打ち"""
        self.lang = 'ja'
        self.input_engine = 'nict'        
        self.rospeex.set_spi_config(language='ja',engine='nict')



        """ for jsk voice understanding """
        rospy.Subscriber("/Tablet/voice", VoiceMessage, self.jsk_voice)



        """ 発話理解APIの準備 """
        self.req = DoCoMoUnderstandingReq()

        self.req.projectKey = rospy.get_param("~req_projectKey", 'OSU')
        self.req.appName = rospy.get_param("~req_appName" ,'')
        self.req.appKey = rospy.get_param("~req_appKey" ,'hoge_app01')
        self.req.clientVer = rospy.get_param("~req_clientVer",  '1.0.0')
        self.req.dialogMode = rospy.get_param("~req_dialogMode",'off')
        self.req.language = rospy.get_param("~req_language", 'ja')
        self.req.userId = rospy.get_param("~req_userId", '12 123456 123456 0')
        self.req.lat = rospy.get_param("~req_lat" , '139.766084')
        self.req.lon = rospy.get_param("~req_lon" , '35.681382')


        """ 雑談対話APIの準備 """
        self.req_chat = DoCoMoChatReq()
        self.req_chat.utt = ""

        self.req_chat.context =  rospy.get_param("~context", "aaabbbccc111222333")
        self.req_chat.nickname = rospy.get_param("~nickname", "ひろゆき")
        self.req_chat.nickname_y = rospy.get_param("~nickname_y", "ヒロユキ")
        self.req_chat.sex = rospy.get_param("~sex", "男")
        self.req_chat.bloodtype = rospy.get_param("~bloodtype", "AB")
        self.req_chat.birthdateY = rospy.get_param("~birthdateY", "1960")
        self.req_chat.birthdateM = rospy.get_param("~birthdateM", "7")
        self.req_chat.birthdateD = rospy.get_param("~birthdateD", "11")
        self.req_chat.age = rospy.get_param("~age", "56")
        self.req_chat.constellations = rospy.get_param("~constellations", "蟹")
        self.req_chat.place = rospy.get_param("~place", "東京")
        self.req_chat.mode = rospy.get_param("~mode", "dialog")
        self.req_chat.t = rospy.get_param("~t", "20")


        """ サービスの起動 """
        rospy.wait_for_service('docomo_sentenceunderstanding')
        self.understanding = rospy.ServiceProxy('docomo_sentenceunderstanding',DoCoMoUnderstanding)

        rospy.wait_for_service('docomo_qa')        
        self.qa = rospy.ServiceProxy('docomo_qa',DoCoMoQa)

        rospy.wait_for_service('docomo_chat')        
        self.chat = rospy.ServiceProxy('docomo_chat',DoCoMoChat)

        self.resp_understanding = DoCoMoUnderstandingRes()
        
        self.nowmode = "CHAT"
        rospy.spin()


    def trcpSay(self, text):
        self.rospeex.say(text, 'ja', 'nict')


    def jsk_voice(self,data):
#        print len(data.texts)
#        for elem in data.texts:
#            print elem
        rospy.loginfo("jsk_voice:%s", data.texts[0])
        self.execTrcpChat(data.texts[0])


    def sr_response(self, message):
        # Rospeexを使うと、文字列の最後に「。」が付くので削除する
        src = message
        sr_dst=src.replace('。', '')
        rospy.loginfo("rospeex:%s", sr_dst)
        self.execTrcpChat(sr_dst)


    """ DoCoMo 知識検索の実行 """
    def execDoCoMoQA(self, message):
        rospy.loginfo("DoCoMo Q&A")
        self.req_qa = DoCoMoQaReq()
        self.req_qa.text = message

        res_qa = self.qa(self.req_qa)
        if res_qa.success:
            # for answer in res_qa.response.answer:
            #     print answer.rank
            #     print answer.answerText
            #     print answer.linkText
            #     print answer.linkUrl
            """
            質問回答のレスポンスコードは、下記のいずれかを返却。
            S020000: 内部のDBからリストアップした回答
            S020001: 知識Q&A APIが計算した回答
            S020010: 外部サイトから抽出した回答候補
            S020011: 外部サイトへのリンクを回答
            E010000: 回答不能(パラメータ不備)
            E020000: 回答不能(結果0件)
            E099999: 回答不能(処理エラー)
            ※Sで始まる場合は正常回答、
            Eで始まる場合は回答が得られていないことを示す。
            """
            rospy.loginfo("DoCoMo Q&A response code:%s",res_qa.response.code)
            if res_qa.response.code == 'S020000':
                rospy.loginfo("DoCoMo Q&A response:%s",res_qa.response.textForDisplay)
                self.trcpSay(res_qa.response.textForSpeech)
            elif res_qa.response.code == 'S020001':
                rospy.loginfo("DoCoMo Q&A response:%s",res_qa.response.textForDisplay)
                self.trcpSay(res_qa.response.textForSpeech)
            elif res_qa.response.code == 'S020010':
                rospy.loginfo("DoCoMo Q&A response:%s",res_qa.response.textForDisplay)
                self.trcpSay(res_qa.response.textForSpeech)
            elif res_qa.response.code == 'S020011':
                rospy.loginfo("DoCoMo Q&A response:%s",res_qa.response.textForDisplay)
                self.trcpSay(res_qa.response.textForSpeech)
            elif res_qa.response.code == 'E010000':
                rospy.loginfo("DoCoMo Q&A response:%s",res_qa.response.textForDisplay)
                self.trcpSay("ごめんなさい、答えが見つかりませんでした")
            elif res_qa.response.code == 'E020000':
                rospy.loginfo("DoCoMo Q&A response:%s",res_qa.response.textForDisplay)
                self.trcpSay("ごめんなさい、答えが見つかりませんでした")
            elif res_qa.response.code == 'E099999':
                rospy.loginfo("DoCoMo Q&A response:%s",res_qa.response.textForDisplay)
                self.trcpSay("ごめんなさい、答えが見つかりませんでした")
            else:
                pass
        else:
            rospy.loginfo("DoCoMo Q&A response:%s","system error")
            return False

        return True


    def execTrcpChat(self, message):
        rospy.loginfo("chat:%s", message)
        #message が特定のキーワードであれば、それに対応した処理を行う
        """ 時間 ->現在時刻を答える"""
        time = re.compile('(?P<time>何時)').search(message)
        if time is not None:
            rospy.loginfo("What Time is it now? :%s", message)        
            d = datetime.datetime.today()
            text = u'%d時%d分です。'%(d.hour, d.minute)

            self.trcpSay(text)
            return True

        # 特定のキーワード処理はここまで
        print self.nowmode
        try:
            """ もし現在の会話モードが「しりとり」なら
                文章理解APIをスキップする

                それ以外なら、文章理解APIで文章を解析する
            """
            if self.nowmode == "CHAIN":
                self.resp_understanding.success = True
                self.resp_understanding.response.commandId = "BC00101"
                self.resp_understanding.response.utteranceText = message
            else:
                self.req.utteranceText = message
                self.resp_understanding = self.understanding(self.req)

            if  self.resp_understanding.success:
                commandId = self.resp_understanding.response.commandId
                rospy.loginfo("<< %s", commandId)

                if commandId == "BC00101":
                    """雑談"""
                    rospy.loginfo("DoCoMo Chat")
                    self.req_chat.utt = message
                    self.res_chat = self.chat(self.req_chat)
                    rospy.loginfo("DoCoMo Chat response:%s",self.res_chat.response)

                    """雑談対話からのレスポンスを設定する"""
                    self.req_chat.mode = self.res_chat.response.mode.encode('utf-8')
                    self.req_chat.context = self.res_chat.response.context.encode('utf-8')

                    if self.nowmode == "CHAIN":
                        if self.res_chat.response.mode == "srtr":
                            print self.nowmode
                            self.nowmode = "CHAIN"                    
                            self.trcpSay(self.res_chat.response.utt)
                        else:
                            print self.nowmode
                            self.nowmode = "CHAT"
                            self.trcpSay(self.res_chat.response.utt)
                    elif self.nowmode == "CHAT":                       
                        if self.res_chat.response.mode == "srtr":
                            print self.nowmode
                            self.nowmode = "CHAIN"                    
                            self.trcpSay(self.res_chat.response.utt)
                        else:
                            print self.nowmode
                            self.nowmode = "CHAT"
                            rospy.loginfo("TRCP Chat response:%s",self.res_chat.response.yomi)
                            self.trcpSay(self.res_chat.response.yomi)





                elif commandId  == "BK00101":
                    """知識検索"""
                    rospy.loginfo(":Q&A")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)

                elif commandId  == "BT00101":
                    """乗換案内"""
                    rospy.loginfo(":Transfer")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)

                elif commandId  == "BT00201":
                    """地図"""
                    rospy.loginfo(":Map")                    
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)

                elif commandId == "BT00301":
                    """天気"""
                    rospy.loginfo(":Weather")                    
                    """お天気検索"""
                    """http://weather.livedoor.com/weather_hacks/webservice"""
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)

                elif commandId == "BT00401":
                    """グルメ検索"""
                    rospy.loginfo(":Restaurant")
                    """ グルなびWebサービス"""
                    """http://api.gnavi.co.jp/api/"""
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)

                    
                elif commandId == "BT00501":
                    """ブラウザ"""
                    rospy.loginfo(":Webpage")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT00601":
                    """観光案内"""
                    rospy.loginfo(":Sightseeing")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT00701":
                    """カメラ"""
                    rospy.loginfo(":Camera")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT00801":
                    """ギャラリー"""
                    rospy.loginfo(":Gallery")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT00901":
                    """通信"""
                    rospy.loginfo(":Coomunincation")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01001":
                    """メール"""
                    rospy.loginfo(":Mail")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01101":
                    """メモ登録"""
                    rospy.loginfo(":Memo input")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01102":
                    """メモ参照"""
                    rospy.loginfo(":Memo output")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01201":
                    """アラーム"""
                    rospy.loginfo(":Alarm")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01301":
                    """スケジュール登録"""
                    rospy.loginfo(":Schedule input")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01302":
                    """スケジュール参照"""
                    rospy.loginfo(":Schedule input")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01501":
                    """端末設定"""
                    rospy.loginfo(":Setting")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT01601":
                    """SNS投稿"""
                    rospy.loginfo(":SNS")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BT90101":
                    """キャンセル"""
                    rospy.loginfo(":Cancel")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BM00101":
                    """地図乗換"""
                    rospy.loginfo(":Map transfer")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                elif commandId == "BM00201":
                    """通話メール"""
                    rospy.loginfo(":Short mail")
                    self.execDoCoMoQA(self.resp_understanding.response.utteranceText)
                    
                else:
                    """発話理解APIで判定不能"""
                    """Undeterminable"""     
                    rospy.loginfo("Undeterminable:%s",self.resp_understanding.response.commandId)
                    self.trcpSay("ごめんなさい、良く聞き取れませんでした。")

            else:
                """発話理解APIがエラーのとき"""
                rospy.loginfo("DoCoMo 発話理解API failed")
                pass
        except:
            """対話プログラムのどこかでエラーのとき"""
            rospy.loginfo("error")
            pass

        return True
Exemplo n.º 16
0
 def __init__(self):
     self._interface = ROSpeexInterface()