Exemplo n.º 1
0
def retrive_printing_status():
  status, data = Retrieve_information_about_the_current_job()
  if status:
    if data['job']['file']['name'] == None:
      tts.getText2VoiceStream2("프린터가 출력중이 아닙니다.")
      return
    tts.getText2VoiceStream2("{0} 파일을 출력중이며, {1}시간 후 종료될 예정입니다. 완료율은 {2}% 입니다.".format(data['job']['file']['name'][:data['job']['file']['name'].find('.')], round(data['progress']['printTimeLeft'] / 3600, 1), round(data['progress']['completion'], 1)))
Exemplo n.º 2
0
def chk_selected_and_print():
  status, data = Retrieve_information_about_the_current_job()
  if status:
    if data['job']['file']['name'] == None:
      tts.getText2VoiceStream2("출력을 위해 선택된 파일이 없습니다. 파일 선택 후 출력을 진행합니다.")
      select_file_by_name()
    tts.getText2VoiceStream2("선택된 파일을 출력합니다.")
    Issue_a_job_command("start")
Exemplo n.º 3
0
def select_file_by_name(): # ~시간이 소요되는 ~, ~시간이 소요되는 ~
  status, data = Retrieve_all_files()
  filename_list = ["."]
  text = ""
  if not status:
    return
  for files in data['files']:
    filename_list.append(files['display'][:files['display'].find('.')])
    text = text + str(round(files['gcodeAnalysis']['estimatedPrintTime'] / 3600, 1)) + " 시간이 소요되는 " + files['display'][:files['display'].find('.')] + ", "
  text = text[:text.__len__()-2] + " 중 몇 번째 파일을 선택하시겠습니까?"
  print(filename_list.__len__())
  tts.getText2VoiceStream2(text)
  while True:
    readval = stt.get_text_from_voice()
    if readval.find("번째") != -1:
      for key, num in count_dic.items():
        if num > filename_list.__len__() - 1:
          break
        if readval.find(key) != -1:
          tts.getText2VoiceStream2("{0}파일을 선택합니다.".format(filename_list[num]))
          result = Issue_a_file_command(filename_list[num])
          if result == 0:
            tts.getText2VoiceStream2("알 수 없는 오류가 발생하였습니다. 처음으로 돌아갑니다.")
          return
    tts.getText2VoiceStream2("이해하지 못하였습니다. 다시 한번 말해주세요.")
  return
Exemplo n.º 4
0
def detect():
    global btn_status
    with MS.MicrophoneStream(RATE, CHUNK) as stream:
        audio_generator = stream.generator()

        for content in audio_generator:

            rc = ktkws.detect(content)
            rms = audioop.rms(content, 2)
            #print('audio rms = %d' % (rms))

            if (btn_status == True):
                rc = 1
                btn_status = False
            if (rc == 1):
                # MS.play_file("../data/sample_sound.wav") # 소리시러
                tts.getText2VoiceStream2("네,")
                return 200
Exemplo n.º 5
0
def call():
    recog = 500
    recog = kws.call('지니야')
    if recog == 200:
        tts.getText2VoiceStream2("네,")
        speech_read()
Exemplo n.º 6
0
def speech_read():
    global coordinate_now
    GPIO.output(31, GPIO.HIGH)
    readval = ""
    readval = stt.get_text_from_voice()
    # 원점으로 이동해 -----
    if readval.find("원점") != -1:
        tts.getText2VoiceStream2("원점으로 이동합니다.")
        Serial.write(bytes("G28;".encode()))
        coordinate_now = [0, 0]
# 가로 방향으로 ~ 만큼 이동해 -----
    elif readval.find("가로") != -1:
        tts.getText2VoiceStream2("X축 방향 {0}로 이동합니다.".format(
            int(re.findall("\d+", readval)[0])))
        if re.findall("\d+", readval):
            moveval = int(re.findall("\d+", readval)[0])
            Serial.write(bytes("G00 X{}.;".format(moveval).encode()))
            coordinate_now[0] = moveval
# 세로 방향으로 ~ 만큼 이동해 -----
    elif readval.find("세로") != -1 or readval.find("새로") != -1:
        tts.getText2VoiceStream2("Y축 방향 {0}로 이동합니다.".format(
            int(re.findall("\d+", readval)[0])))
        if re.findall("\d+", readval):
            moveval = int(re.findall("\d+", readval)[0])
            Serial.write(bytes("G00 Y{}.;".format(moveval).encode()))
            coordinate_now[1] = moveval
# 물체 잡아 -----
    elif readval.find("물체") != -1 and readval.find("잡아") != -1:
        tts.getText2VoiceStream2("잡을게요")
        Serial.write(bytes("G01;".encode()))
        coordinate_now = [0, 0]
# 현재 위치의 물체 학습해줘 -----
    elif readval.find("학습") != -1:
        tts.getText2VoiceStream2("현재 위치의 색상을 학습합니다. 카메라에 감지된 색상 코드를 읽는 중입니다.")
        endtime = time.time() + 3
        finded_center = []
        finalfound = False  # 알 수 없는 색상 발견여부
        colorfound = False  # 알 수 있는 색상 발견여부
        while True:
            if endtime <= time.time():
                break
            image = getimage()
            find_color_list, isfind = object_detection(getimage())
            debugimage = copy.deepcopy(image)
            debugimage, _ = labeling(debugimage, find_color_list)
            if isfind:  # 알 수 있는 색상이 감지된 경우
                colorfound = True
                finalkey = ""
                for key in find_color_list:
                    finalkey = key
            if '?' in find_color_list:
                finded_center = find_color_list
                finalfound = True
            cv2.imshow("asdf", debugimage)
            cv2.waitKey(1)
        if finalfound and not colorfound:
            print(finded_center)
            tts.getText2VoiceStream2(
                "X{0}, Y{1} 좌표에서 물체를 발견하였습니다. 색상의 이름을 말해주세요.".format(
                    finded_center['?']['location'][0][0],
                    finded_center['?']['location'][0][1]))
        elif colorfound:
            tts.getText2VoiceStream2("{0}이 발견되었습니다. 처음으로 돌아갑니다.".format(
                color_to_korean[finalkey]))
            return
        else:
            tts.getText2VoiceStream2("물체를 발견하지 못하였습니다. 처음으로 돌아갑니다.")
            return
        while True:
            inputcol = stt.get_text_from_voice()
            engkey, korkey, status = text_to_key(inputcol)
            print(engkey, korkey, status)
            if status == 0:  # 찾지못함
                tts.getText2VoiceStream2("이해하지 못했습니다. 다시 한번 말해주세요.")
                continue
            elif status == 2:  # 취소
                tts.getText2VoiceStream2("취소합니다.")
                return
            else:
                tts.getText2VoiceStream2("{0}을 선택하셨습니다.".format(korkey))
                print(engkey, finded_center['?']['hsv'][0])
                add_hsv_code(engkey, finded_center['?']['hsv'][0])
                return
# 인공지능 물체인식 시작 -----
    elif readval.find("인공지능") != -1:
        tts.getText2VoiceStream2("인공지능 작동을 시작합니다. 우선 전체 스캔을 시작합니다.")
        image = get_entire_image()
        find_color_list, isfind = object_detection(image)
        if isfind:
            _, ttsText = labeling(copy.deepcopy(image), find_color_list)
            tts.getText2VoiceStream2(ttsText)  # TTS: 어떤 물체를 선택할까요?
            while True:
                inputcol = stt.get_text_from_voice()
                engkey, korkey, status = text_to_key(inputcol)
                if status == 0:  # 찾지못함
                    tts.getText2VoiceStream2("이해하지 못했습니다. 다시 한번 말해주세요.")
                    continue
                elif status == 2:  # 취소
                    tts.getText2VoiceStream2("취소합니다.")
                    return
                else:
                    if engkey in find_color_list:
                        tts.getText2VoiceStream2(
                            "{0}을 선택하셨습니다.".format(korkey))
                        break
                    else:
                        tts.getText2VoiceStream2(
                            "{0}은 인식되지 않은 색상입니다. 처음으로 돌아갑니다.".format(korkey))
                        return
            px_to_mm_and_go(find_color_list, engkey, 1)
            tts.getText2VoiceStream2(
                "X{0}, Y{1} 좌표로 이동한 후 최종 물체 인식을 시작합니다.".format(
                    coordinate_now[0], coordinate_now[1]))
            endtime = time.time() + 10
            finded_center = []
            finalfound = False
            while True:
                if endtime <= time.time():
                    break
                image = getimage()
                find_color_list, isfind = object_detection(image)
                if isfind:
                    finalfound = True
                    debugimage, _ = labeling(copy.deepcopy(image),
                                             find_color_list)
                    cv2.imshow("debug", debugimage)  # 디버그이미지 출력
                    finded_center = find_color_list
                cv2.waitKey(1)
            print(finded_center)
            if finalfound:
                px_to_mm_and_go(finded_center, engkey, 2)
                tts.getText2VoiceStream2("최종 물체 인식에 성공하였습니다. 물체를 잡습니다.")
            else:
                tts.getText2VoiceStream2("최종 물체 인식에 실패하였습니다. 처음으로 돌아갑니다.")
                Serial.write(bytes("G28;".encode()))
                return
        else:
            tts.getText2VoiceStream2("어떠한 물체도 발견되지 않았습니다. 처음으로 돌아갑니다.")
            Serial.write(bytes("G28;".encode()))
            return


# 음성인식 결과 없음 -----
    else:
        tts.getText2VoiceStream2("이해하지 못했습니다.")
    GPIO.output(31, GPIO.LOW)
Exemplo n.º 7
0
            return


# 음성인식 결과 없음 -----
    else:
        tts.getText2VoiceStream2("이해하지 못했습니다.")
    GPIO.output(31, GPIO.LOW)
""" 호출 """


def call():
    recog = 500
    recog = kws.call('지니야')
    if recog == 200:
        tts.getText2VoiceStream2("네,")
        speech_read()


""" Main 함수 """


def main():
    while 1:
        call()
        cv2.destroyAllWindows()


""" 직접 코드 실행시 작동 """
if __name__ == '__main__':
    tts.getText2VoiceStream2("호출하기 위해 지니야 를 불러주세요.")
    main()
def speech_read(mode):
    GPIO.output(31, GPIO.HIGH)
    readval = ""
    readval = stt.get_text_from_voice()
    # 원점으로 이동해 -----
    if readval.find("원점") != -1:
        print("원점이동")
        tts.getText2VoiceStream2("원점으로 이동합니다.")
        Serial.write(bytes("G28;".encode()))
# 가로 방향으로 ~ 만큼 이동해 -----
    elif readval.find("가로") != -1:
        print("X축 이동")
        if re.findall("\d+", readval):
            moveval = int(re.findall("\d+", readval)[0])
            tts.getText2VoiceStream2("가로축 방향 {0}으로 이동합니다.".format(moveval))
            Serial.write(bytes("G00 X{}.;".format(moveval).encode()))
# 세로 방향으로 ~ 만큼 이동해 -----
    elif readval.find("세로") != -1 or readval.find("새로") != -1:
        print("Z축 이동")
        if re.findall("\d+", readval):
            moveval = int(re.findall("\d+", readval)[0])
            tts.getText2VoiceStream2("세로축 방향 {0}으로 이동합니다.".format(moveval))
            Serial.write(bytes("G00 Z{}.;".format(moveval).encode()))
# 스틱 작동해 -----
    elif readval.find("스틱") != -1:
        print("잡잡")
        tts.getText2VoiceStream2("스틱을 작동합니다.")
        Serial.write(bytes("G01;".encode()))
# 인공지능 물체 인식 시작 -----
    elif readval.find("인공지능") != -1:
        tts.getText2VoiceStream2("인공지능 물체 인식을 시작합니다. 먼저 전체 물체 스캔을 시작합니다.")
        print("인공지능 작동")
        Serial.write(bytes("G28;".encode()))
        time.sleep(5)
        print("작동 시작")
        get_hsv_data()
        isfind = find_color_name()
        if not isfind:
            tts.getText2VoiceStream2(
                "어떠한 공도 찾지 못하였습니다. 정상적으로 인식하지 못한 경우 학습을 진행해주시기 바랍니다.")
            return
        text = generate_tts_from_color()
        tts.getText2VoiceStream2(text)
        while True:
            readval = stt.get_text_from_voice()
            isbreak = False
            if readval.find("취소") != -1:
                tts.getText2VoiceStream2("취소합니다.")
                break
            else:
                for key, value in color_to_english.items():
                    if readval.find(
                            key) != -1 and value in find_color_num_list:
                        get_ball_with_stt(value)
                        isbreak = True
                        break
            if isbreak:
                break
            else:
                tts.getText2VoiceStream2("이해하지 못했습니다. 다시 한번 말해주세요.")
        cv2.destroyAllWindows()


# 현재 위치의 물체 학습해줘 -----
    elif readval.find("학습") != -1:
        tts.getText2VoiceStream2("현재 위치의 색상을 학습합니다. 카메라에 감지된 색상 코드를 읽는 중입니다.")
        hsv_data = get_hsv_data_now()
        cv2.destroyAllWindows()
        if color_data_list[0] != '?':
            tts.getText2VoiceStream2("{0}이 감지되었습니다. 처음으로 돌아갑니다.".format(
                color_to_korean[color_data_list[0]]))
            return
        else:
            tts.getText2VoiceStream2("색상의 이름을 말해주세요.")
            while True:
                readval = stt.get_text_from_voice()
                isbreak = False
                if readval.find("취소") != -1:
                    tts.getText2VoiceStream2("취소합니다.")
                    break
                else:
                    for key, value in color_to_english.items():
                        if readval.find(key) != -1:
                            tts.getText2VoiceStream2(
                                "{0}을 학습 데이터에 더합니다.".format(
                                    color_to_korean[value]))
                            add_hsv_code(value, hsv_data)
                            isbreak = True
                            break
                if isbreak:
                    break
                else:
                    tts.getText2VoiceStream2("이해하지 못했습니다. 다시 한번 말해주세요.")
    else:
        tts.getText2VoiceStream2("이해하지 못했습니다.")

    GPIO.output(31, GPIO.LOW)
Exemplo n.º 9
0
def speech_read():
  GPIO.output(31, GPIO.HIGH)
  GPIO.output(31, GPIO.LOW)
  readval = ""
  readval = stt.get_text_from_voice()
# 파일 선택 -----
  if readval.find("파일") != -1 and readval.find("선택") != -1: 
    select_file_by_name()
    return
  if readval.find("축") != -1 and readval.find("방향") != -1 and re.findall("\d+", readval).__len__() > 0:
# X축 방향으로 ~만큼 이동해 -----
    if readval.find("x") != -1 or readval.find("X") != -1: 
      move_axis('X', int(re.findall("\d+", readval)[0]))
      tts.getText2VoiceStream2("X축 방향 {0}로 이동합니다.".format(int(re.findall("\d+", readval)[0])))
      return
# Y축 방향으로 ~만큼 이동해 -----
    if readval.find("y") != -1 or readval.find("Y") != -1: 
      move_axis('Y', int(re.findall("\d+", readval)[0]))
      tts.getText2VoiceStream2("Y축 방향 {0}로 이동합니다.".format(int(re.findall("\d+", readval)[0])))
      return
# Z축 방향으로 ~만큼 이동해 -----
    if readval.find("z") != -1 or readval.find("Z") != -1: 
      move_axis('Z', int(re.findall("\d+", readval)[0]))
      tts.getText2VoiceStream2("Z축 방향 {0}로 이동합니다.".format(int(re.findall("\d+", readval)[0])))
      return
# 원점 복귀 -----
  if readval.find("원점") != -1: 
    move_axis('H', 123)
    tts.getText2VoiceStream2("원점으로 복귀합니다.")
    return
  if readval.find("알려줘") != -1:
# 현재 온도 알려줘 -----
    if readval.find("온도") != -1: 
      retrive_temperature()
      return
# 출력 현황 알려줘 -----
    if readval.find("출력") != -1: 
      retrive_printing_status()
      return

  if readval.find("설정해") != -1:
    if readval.find("온도") != -1 and re.findall("\d+", readval).__len__() > 0:
# 핫엔드 온도 ~도로 설정해줘 -----
      if readval.find("핫 &") != -1: 
        tts.getText2VoiceStream2("핫엔드 온도를 {0}도로 설정합니다.".format(int(re.findall("\d+", readval)[0])))
        Issue_a_tool_command(int(re.findall("\d+", readval)[0]))
        return
# 히팅베드 온도 ~도로 설정해줘 -----
      if readval.find("heating") != -1: 
        tts.getText2VoiceStream2("히팅베드 온도를 {0}도로 설정합니다.".format(int(re.findall("\d+", readval)[0])))
        Issue_a_bed_command(int(re.findall("\d+", readval)[0]))
        return
        
  if readval.find("출력") != -1:
# 출력 재시작해 -----
    if readval.find("재시작") != -1: 
      tts.getText2VoiceStream2("출력을 재시작 합니다.")
      Issue_a_job_command("resume")
      return
# 출력 시작해 -----
    if readval.find("시작") != -1: 
      tts.getText2VoiceStream2("출력을 시작합니다.")
      Issue_a_job_command("start")
      return
# 출력 일시중지해 -----
    if readval.find("일시") != -1:
      tts.getText2VoiceStream2("출력을 일시중지 합니다.")
      Issue_a_job_command("pause")
      return
# 출력 정지해 -----
    if readval.find("정지") != -1: 
      tts.getText2VoiceStream2("출력을 정지합니다.")
      Issue_a_job_command("stop")
      return
  else:
    tts.getText2VoiceStream2("이해하지 못했습니다.")
Exemplo n.º 10
0
def retrive_temperature():
  result, data = Retrieve_the_current_printer_state()
  if not result:
    tts.getText2VoiceStream2("알 수 없는 오류가 발생하였습니다. 나중에 다시 시도해주세요.")
    return
  tts.getText2VoiceStream2("노즐 온도는 {0}도, 히팅베드 온도는 {1}도 입니다.".format(data['temperature']['tool0']['actual'], data['temperature']['bed']['actual']))