예제 #1
0
 def standby(self, prompt=False):
     logger.info("Standby")
     if prompt:
         Speaker.play_async("如果需要協助再呼叫我。")
         Information.set_user_speaking(False, 5)
     else:
         Information.set_user_speaking(False, 1)
     self._user_listener.listen_hotword()
예제 #2
0
    def __init__(self, sub1, is_simulation=False):
        super(Sub3, self).__init__()
        logger.debug("__init__")

        Information.set_sub1(sub1)
        self.dialogue_client = DialogueClient.get_instance()
        self.running = True
        self.is_simulation = is_simulation
        self.sub4 = None
예제 #3
0
def __process_indoor(client, target):
    dest = Information.parse_indoor_destination(target)
    if dest is None:
        Speaker.play("很抱歉,目前我還不知道怎麼帶你去" + target)
        client.standby(True)
    else:
        Speaker.play("好的,我現在開始找尋附近的" + target)
        Information.set_indoor_destination(dest)
        client.standby()
예제 #4
0
파일: Sub4.py 프로젝트: mfshiu/dialogue-nav
    def update_sim_kanbans(self):
        logger.debug("update_sim_kanbans: 0")
        if not Information.is_indoor():
            return  # Not indoor, don't update

        self.sim_kanbans_index += 1
        if self.sim_kanbans_index >= len(self.sim_kanbans):
            self.sim_kanbans_index = 0
        kanban = self.sim_kanbans[self.sim_kanbans_index]
        Information.set_information("kanban_indoor", kanban)
예제 #5
0
def implement_intent(client, query_result):
    target = query_result.parameters['scene']

    if len(target) == 0:
        msg = "我沒聽清楚要切換到哪個場景,請再說一遍。"
        Speaker.play(msg)
        client.listen_user()
    else:
        if "室內" == target:
            Information.set_indoor(True)
            Speaker.play("好的,已經切換到" + target)
        elif "室外" == target:
            Information.set_indoor(False)
            Speaker.play("好的,已經切換到" + target)
        else:
            Speaker.play("很抱歉,我還不知道怎麼切換到" + target)
        client.standby(True)
예제 #6
0
파일: Sub4.py 프로젝트: mfshiu/dialogue-nav
    def speak_kanban(self, kanban):
        if Information.is_user_speaking():
            return

        msg = ""    # msg = format("%s方%s公尺處,有一個%s標示指向%s方")
        if kanban["user_direction"] is not None:
            msg += self.gen_direction_text(kanban["user_direction"])
        if kanban["distance"] is not None:
            msg += str(kanban["distance"]) + "步左右,"
        if kanban["name"] is not None:
            msg += "有一個" + Information.get_indoor_destination_text(kanban["name"]) + "標示"
        if "direction" in kanban and kanban["direction"] is not None:
            msg += "指向" + self.gen_direction_text(kanban["direction"])
            msg += ",請依指示轉彎後繼續前進"

        logger.info(msg)
        self.play_sound(msg, quieter=True)
예제 #7
0
    def run(self):
        self.listen_hotword()
        while self.running:
            if self.job_count > 0:
                Speaker.mute()
                Information.set_user_speaking(True)
                # try:
                self.__record(self.limit_seconds)
                # except Exception as ex:
                #     logger.error("Do record error!\n%s", str(ex))
                Information.set_user_speaking(False)
                Speaker.unmute()
                self.job_count = 0
                time.sleep(1)

            time.sleep(0.01)

        logger.info("terminated")
예제 #8
0
def get_user_location():
    # loc = gmaps.geolocate()
    # return 25.0230239, 121.2210628
    # return loc['location']['lat'], loc['location']['lng']
    loc = info.get_location()
    if loc is None:
        geo = gmaps.geolocate()
        loc = geo['location']['lat'], geo['location']['lng']
    return loc[0], loc[1]
예제 #9
0
파일: Sub1.py 프로젝트: mfshiu/dialogue-nav
    def __walk_timer(self):
        # arrived = Information.get_information('sub1_arrived')
        dest = Information.get_information('sub1_destination')
        # 如果還沒到且目的地不同,就會前進
        if dest is not None:
            # dest = Information.get_information('sub1_destination')
            if not Helper.is_arrived(self.current_location, dest):
                if len(self.locations) > 0:
                    self.current_location = self.locations.pop(0)
                    Information.set_information("location",
                                                self.current_location)
                    logger.debug("walk to: %s", str(self.current_location))
            if Helper.is_arrived(self.current_location, dest):
                logger.warn("Arrived.")
                Information.set_information('sub1_destination', None)
                # Information.set_information("sub1_arrived", True)

        if self.running:
            Timer(5, self.__walk_timer).start()
예제 #10
0
    def __arrived_outdoor(self, key, value):
        if len(self.destinations) == 0:
            return
        Information.set_outdoor_destination(None, None)

        dest = self.destinations.pop()
        Speaker.play("您已經抵達" + dest.name)
        self.destinations.clear()
        # 取消 2021/9/27
        # count = len(self.destinations)
        # if count > 0:
        #     next_dest = self.destinations[count - 1]
        #     Speaker.play("接下來我們將繼續前往" + next_dest.name)
        #     Speaker.play("現在開始請聽我的指示前進")
        #     Information.set_outdoor_destination(next_dest.coordinate, next_dest.dest_type)
        # else:
        #     self.standby(True)
        Information.set_outdoor_destination(None, None)
        self.standby(True)
예제 #11
0
파일: Sub4.py 프로젝트: mfshiu/dialogue-nav
 def get_kanban(self, kanban_name):
     viewed_kanbans = Information.get_indoor_kanbans()
     if viewed_kanbans is None:
         return None
     for kanban in viewed_kanbans:
             logger.debug("Kanban: %s", str(kanban))
             if "name" in kanban:
                 if kanban_name == str(kanban["name"]):
                     return kanban
     return None
예제 #12
0
    def run(self):

        self.dialogue_client.start()

        # if self.is_simulation:
        #     self.sub1 = Sub1()
        #     self.sub1.start()
        self.sub4 = Sub4(self.is_simulation)
        self.sub4.start()

        Information.set_indoor(False)

        while self.running:
            if self.dialogue_client.is_terminated:
                self.terminate()
            time.sleep(1)
        if not self.dialogue_client.is_terminated:
            self.dialogue_client.shutdown()
        logger.info("terminated")
        return
예제 #13
0
def implement_intent(client, query_result):
    target = query_result.parameters['location']

    if len(target) == 0:
        msg = "對不起我沒聽清楚你要去的地方,請您再說一遍。"
        Speaker.play(msg)
        client.listen_user()
    else:
        if Information.is_indoor():
            __process_indoor(client, target)
        else:
            __process_outdoor(client, target)
예제 #14
0
파일: Sub4.py 프로젝트: mfshiu/dialogue-nav
    def walk_timer(self):
        # logger.debug("walk_timer begin")
        arrived = Information.get_information('sub4_arrived')
        if not arrived:
            dest = Information.get_information('sub4_destination')
            kanban_name = Information.get_indoor_destination_text(dest)
            kanban = self.get_kanban(dest)
            if kanban is not None:
                distance = kanban["distance"]
                if distance is not None:
                    if float(distance) <= 0:
                        logger.warn("Arrived.")
                        self.play_sound("您已經抵達" + kanban_name)
                        Information.set_information("sub4_arrived", True)
                    else:
                        self.speak_kanban(kanban)
                else:
                    self.speak_kanban(kanban)
            else:
                # logger.debug("walk_timer 1, is_user_speaking: %s" % (Information.is_user_speaking(),))
                if not Information.is_user_speaking():
                    # logger.debug("walk_timer 2")
                    self.play_sound("我看不見有關" + kanban_name + "的標示,請看看四週或往前走一下", quieter=True)

            obstacle = self.get_kanban("99")
            if obstacle is not None:
                self.speak_obstacle(obstacle)
예제 #15
0
def implement_intent(client, query_result):
    kanbans = Information.get_indoor_kanbans() or []

    all_kanbans = []
    for k in kanbans:
        if 'name' in k:
            all_kanbans.append(Information.get_indoor_destination_text(k["name"]))
    # all_kanbans = [Information.get_indoor_destination_text(k["name"]) for k in kanbans]

    if len(all_kanbans) == 0:
        msg = "前方看不見任何標示,請轉頭看看四週"
        Speaker.play(msg)
        client.standby()
    else:
        if len(all_kanbans) == 1:
            msg = "前面的指標只有一個" + all_kanbans[0] + "標示"
        else:
            msg = "前面的指標有" + ",".join(all_kanbans[:-1])
            msg += "和" + all_kanbans[-1]
        msg += ", 請告訴我你想去的地方"
        Speaker.play(msg)
        client.listen_user()
예제 #16
0
    def __on_message(self, client, db, msg):
        data = msg.payload.decode('utf-8', 'ignore')
        write_log("topic: %s, data: %s" % (msg.topic, data))
        if data:
            try:
                data = json.loads(data)
            except:
                write_log("[ERROR] json.loads(data)")
                topic = ""
                data = {}

        if "location" == msg.topic:
            self.location = ([data["lat"], data["lng"]], [True])
        elif "awakable" == msg.topic:
            self.awakable = "on" == data["status"]
        elif "indoor" == msg.topic:
            self.indoor = "on" == data["status"]
        elif "kanban_indoor" == msg.topic:
            Information.set_indoor_kanbans(data)
        elif "arrived" == msg.topic:
            self.arrived = "on" == data["status"]
        elif "echo" == msg.topic:
            write_log("An echo got.")
예제 #17
0
def implement_intent(client, query_result):
    if Information.is_indoor():
        dest = Information.get_indoor_destination()
        if dest is not None:
            Information.stop_indoor_destination()
            msg = "好的,己停止前往" + Information.get_indoor_destination_text(dest)
            Speaker.play(msg)
    else:
        dest = client.get_current_destination()
        if dest is not None:
            Information.stop_outdoor_destination()
            msg = "好的,己停止前往" + dest.name
            Speaker.play(msg)
    client.standby(True)
예제 #18
0
def __find_place(place):
    max_meters = 3000
    name, coord, dist = NavHelper.get_nearest_place(place)
    if name is None:
        return None

    name2, coord2 = Information.find_similar_location(name)
    if name2:
        d = NavHelper.get_walking_distance(coord2)
        if d <= max_meters:
            name, coord, dist = name2, coord2, d

    if dist <= max_meters:
        return Destination(name, coord, dist)
    else:
        return None
예제 #19
0
    def start(self):
        Speaker.play_async("HI,我叫小美,你好。")
        # Speaker.play_async("HI How are you")

        if not os.path.exists("user"):
            os.makedirs("user")
        if not os.path.exists("output"):
            os.makedirs("output")

        self._user_listener = UserListener.UserListener(
            args=(self.user_words, ))
        self._user_listener.start()

        self._user_processor = UserProcessor.UserProcessor(
            args=(self.user_words, self))
        self._user_processor.start()

        Information.subscribe('sub1_arrived', self.__arrived_outdoor, True)
        Information.subscribe('sub4_arrived', self.__arrived_indoor, True)
        Information.start()
        Information.set_indoor(True)

        self.is_terminated = False
예제 #20
0
파일: Sub4.py 프로젝트: mfshiu/dialogue-nav
 def cancel_destination(self):
     dest = Information.get_information('sub4_destination')
     if dest is not None:
         self.play_sound("己停止前往" + dest)
     Information.set_information("sub4_arrived", True)
예제 #21
0
 def __arrived_indoor(self, key, value):
     if Information.get_indoor_destination() is None:
         return
     # Speaker.play("您已經抵達" + dest.name)
     self.standby(True)
예제 #22
0
 def add_destination(self, dest):
     self.destinations.append(dest)
     Information.set_outdoor_destination(dest.coordinate, dest.dest_type)
예제 #23
0
 def shutdown(self):
     Speaker.play("我會想你的")
     Information.terminate()
     self._user_processor.terminate()
     self._user_listener.terminate()
     self.is_terminated = True
예제 #24
0
def __stop_playing():
    Information.set_user_speaking(False)
    global _is_playing
    _is_playing = False
예제 #25
0
 def is_speaking(self):
     return Information.is_user_speaking()
예제 #26
0
 def update_kanbans(self, kanbans):
     Information.set_indoor_kanbans(json.loads(kanbans))
예제 #27
0
from dialogue import Information
import time


def callback01(name, value):
    print("%s is changed to: %s" % (name, value))


Information.subscribe('time', callback01)
Information.start()

time.sleep(10)
Information.terminate()
예제 #28
0
def __start_playing():
    Information.set_user_speaking(True)
    global _is_playing
    _is_playing = True