Ejemplo n.º 1
0
def implement_intent(client, resp):
    logger.debug("query_result: %s" % (resp,))
    msg = None
    if resp.fulfillment_text:
        msg = resp.fulfillment_text
    if msg:
        Speaker.play(msg)
    client.standby()
Ejemplo n.º 2
0
def implement_intent(client, query_result):
    Speaker.play("好的,請繼續聽我的指示前進")
    dest = nav.get_ready_destination()
    if dest:
        client.add_destination(dest)
    else:
        Speaker.play("很抱欺我不知道要如何前往。")
    client.standby()
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
def implement_intent(client, resp):
    if resp.fulfillment_text:
        msg = resp.fulfillment_text
    else:
        msg = "其實我也不清楚創新是什麼"
    Speaker.play(msg)
    client.listen_user()
    client.standby()
Ejemplo n.º 5
0
def implement_intent(client, resp):
    logger.debug("query_result: %s" % (resp, ))
    if resp.fulfillment_text:
        msg = resp.fulfillment_text
    else:
        msg = "其實我也不清楚創新是什麼"
    Speaker.play(msg)
    client.listen_user()
    client.standby()
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
def implement_intent(client, query_result):
    dest = nav.get_ready_destination()
    if dest is not None:
        Speaker.play("好的,現在開始請聽我的指示前進")
        client.add_destination(dest)
        nav.set_ready_destination(None)
    else:
        logger.error("No destination.")
    client.standby()
Ejemplo n.º 8
0
def implement_intent(dialogue_client, query_result):
    if query_result.fulfillment_text:
        if query_result.fulfillment_text:
            Speaker.play(query_result.fulfillment_text)
        else:
            Speaker.play("請您再說一遍。")
        dialogue_client.listen_user()
    else:
        dialogue_client.standby()
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def response_dialogflow(req):
    reply_msg = '很抱歉我沒聽懂,請再說一次。'
    query = req.get("queryResult")
    if query.get("action") == "NavStart":
        params = query.get("parameters")
        if params and params.get("location"):
            destination = params.get("location")
            reply_msg = '請稍候,我查一下附近的' + destination
            start_nav(destination)
        else:
            reply_msg = '我沒聽懂地點,請再說一次。'

    Speaker.play(reply_msg)
    res_json = {'fulfillmentText': reply_msg}
    return res_json
Ejemplo n.º 12
0
    def __record(self):
        logger.info("---recording---")
        self.speaking = False

        audio = pyaudio.PyAudio()
        audio_stream = audio.open(format=FORMAT,
                                  channels=CHANNELS,
                                  rate=RATE,
                                  input=True,
                                  frames_per_buffer=CHUNK_SIZE)
        sample_size = audio.get_sample_size(FORMAT)
        voice_data = []
        head_voice_count = 0
        rear_zero_count = 0
        is_start_speaking = False
        silence_count = RATE // CHUNK_SIZE * 0.25
        i = -1
        while not Speaker.is_playing():
            i += 1
            if i > 1000 and not is_start_speaking:
                logger.debug("Quit recording.")
                break
            time.sleep(0.03)
            chunk_data = audio_stream.read(CHUNK_SIZE)

            zero_cnt = chunk_data.count(0)
            if is_start_speaking:
                if zero_cnt < VOICE_THRESHOLD:
                    rear_zero_count = 0
                else:
                    rear_zero_count += 1
                if rear_zero_count > silence_count:
                    self.speaking = False
                    logger.debug("Stop voice, i = " + str(i))
                    break
            else:
                if zero_cnt < VOICE_THRESHOLD:
                    head_voice_count += 1
                else:
                    head_voice_count = 0
                if head_voice_count > 2:
                    is_start_speaking = True
                    self.speaking = True
                    logger.debug("Start voice, i = " + str(i))
            if zero_cnt < VOICE_THRESHOLD:
                voice_data.append(chunk_data)
                if len(voice_data) > 100:
                    break
                # logger.debug("len(voice_data): %d", len(voice_data))

        audio_stream.stop_stream()
        audio_stream.close()
        audio.terminate()

        logger.debug("Done recording, chunk size: " + str(len(voice_data)))
        if len(voice_data) > 0:
            output_filename_flac = self.write_to_flac(voice_data, sample_size)
            self.user_words.put(output_filename_flac)
Ejemplo n.º 13
0
    def play_sound(self, msg, play_async=False, quieter=False):
        # logger.debug("play_sound: 0")
        now = datetime.now()
        if msg == self.last_kanban_msg:
            # logger.debug("play_sound: 1")
            diff = now - self.last_kanban_msg_time
            if diff.total_seconds() < 8:
                logger.warning("Skip message: " + msg)
                return

        self.last_kanban_msg = msg
        self.last_kanban_msg_time = now

        if not Speaker.is_playing():
            if play_async:
                Speaker.play_async(msg)
            else:
                Speaker.play(msg, quieter)
Ejemplo n.º 14
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")
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
def __process_outdoor(client, target):
    msg = "好的,我現在為您找尋附近的" + target
    Speaker.play(msg)
    dest = __find_place(target)
    if dest:
        current_dest = client.get_current_destination()
        if current_dest:
            Speaker.play("最近的{}是{},距離{}公尺。".format(target, dest.name, dest.distance))
            msg = "但是您正在前往{}的路上,確定要先去{}嗎?".format(current_dest.name, target)
            client.ask_user(msg)
            Speaker.play(msg)
            # Speaker.play("您正在前往{}的途中".format(current_dest.name))
            # Speaker.play("最近的{}是{},距離{}公尺,在去{}之前要先過去那裡嗎?".format(target, d.name, d.distance, current_dest.name))
        else:
            Speaker.play("最近的{}是{},距離{}公尺,要我帶您過去嗎?".format(target, dest.name, dest.distance))
        set_ready_destination(dest)
        client.listen_user()
    else:
        Speaker.play("很抱歉,我找不到附近的{},".format(target))
        client.standby()
Ejemplo n.º 17
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()
Ejemplo n.º 18
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
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
def implement_intent(client, query_result):
    Speaker.play("好的,如有需要再呼叫我")
    client.standby()
Ejemplo n.º 21
0
# if __name__ == '__main__':
#     # manager = Manager()
#     # sub3 = Sub3(manager.dict(), is_simulation=False)
#     t = threading.Thread(target=job)
#     t.start()
#     t.join()

if __name__ == '__main__':
    sub3 = Sub3(Sub1_api(), is_simulation=True)

    def signal_handler(signal, frame):
        sub3.terminate()

    signal.signal(signal.SIGINT, signal_handler)

    sub3.start()

    # sub3.play_sound("子三放音測試")


    def shutdown():
        sub3.terminate()

    while sub3.running:
        Speaker.process_pyttsx3()
        time.sleep(0.1)

    print("System terminated.")
    # while self.running:
    # threading.Timer(5, shutdown).start()
Ejemplo n.º 22
0
def test_timer():
    # t = Timer(5.0, test_timer)
    # t.start()
    Speaker.play("時間到")
    print("hello, world")
Ejemplo n.º 23
0
def do_start_nav(destination):
    time.sleep(5)
    Speaker.play("附近有捷運領航站,要我帶您過去嗎?")
Ejemplo n.º 24
0
 def play_sound(self, msg, play_async=False):
     if not Speaker.is_playing():
         if play_async:
             Speaker.play_async(msg)
         else:
             Speaker.play(msg)
Ejemplo n.º 25
0
def implement_intent(dialogue_client, query_result):
    Speaker.play("關機後系統就不會再回應了,要重新啟動才行,您確定嗎?")
    dialogue_client.listen_user()
Ejemplo n.º 26
0
 def shutdown(self):
     Speaker.play("我會想你的")
     Information.terminate()
     self._user_processor.terminate()
     self._user_listener.terminate()
     self.is_terminated = True
Ejemplo n.º 27
0
 def __detected_hotword(self):
     logger.debug("Hotword is detected.")
     self.__stop_listen_hotword()
     Speaker.play_sound("./dialogue/resources/where_to_go.mp3")
     self.listen()
Ejemplo n.º 28
0
def implement_intent(dialogue_client, query_result):
    Speaker.play("好的,我關機了,再見。")
    dialogue_client.shutdown()
Ejemplo n.º 29
0
 def run(self):
     while self.running:
         if not Speaker.is_playing():
             self.__record()
         time.sleep(0.1)
     logger.info("terminated")