def speech_recog(): for i in range(5): # 5번까지만 인식해보고 안되면 return false try: answer = STT.main() print(answer) # for check return answer except UnboundLocalError: if i < 4: pygame.play_text("please_speech_again.mp3") return "not_recog"
def print_q(key, qlist, kind): if kind == 'food': sid = 0 elif kind == 'hobby': sid = 1 elif kind == 'friend': sid = 2 for idx, q in enumerate(qlist): TTS_en.tts(q) pygame.play_text("sound.mp3") answer = speech_recog() print(answer) # for check if answer == "not_recog": #"대답하기 어렵구나, 다음에 또 불러줘" pygame.play_text("noanswer.mp3") # 사용자가 답을 안했을 때 return False if check_mp(answer, key, idx, kind): accDB.insert_Freetalk_Answer(sid, key, idx, answer, 1) continue # 다음 질문 하기 else: pygame.play_text("incorrect.mp3") # 이상한 대답을 했을때 (임의) return False # "즐거운 시간이였어" pygame.play_text("fun_en_talk.mp3") sleep(1) return True
def freetalking(): pygame.play_text("let_talk.mp3") init_food_Qlist() init_hobby_Qlist() init_friend_Qlist() food_idx, hobby_idx, friend_idx = set(), set(), set() food_idx.add(random.choice([0, 1])) hobby_idx.add(random.choice([0, 1])) friend_idx.add(random.choice([0])) for idx in food_idx: if not print_q(idx, food_Qlist[idx], 'food'): continue for idx in hobby_idx: if not print_q(idx, hobby_Qlist[idx], 'hobby'): continue for idx in friend_idx: if not print_q(idx, friend_Qlist[idx], 'friend'): continue
import pygametest as pygame import reading import interaction import time from collections import defaultdict def call(): try: speech = STT.main() keywords = ["리", "버"] for keyword in keywords: if keyword in speech: return True else: return False except UnboundLocalError: #pygame.play_text("please_speech_again.mp3") return False if __name__ == "__main__": while True: while True: if call(): pygame.play_text( "birdsong_real_1.wav") # 미리 mp3파일로 저장해놓았다가 출력하는 것만 구현 interaction.choose() continue
def choose(): # TTS.tts("책 읽어줄까? 아니면 나랑 애기할래?") pygame.play_text("choose.mp3") # 미리 mp3파일로 저장해놓았다가 출력하는 것만 구현 sleep(1) answer = speech_recog() if answer == "not_recog": pygame.play_text("call_me_again.mp3") return keywords_b = ["책", "첵", "채", "체"] keywords_t = ["얘", "예", "이", "야"] for keyword in keywords_b: if keyword in answer: reading.reading() sleep(1) reading.quiz() sleep(1) reading.book_report() pygame.play_text("fun_talk.mp3") pygame.play_text("call_me_again.mp3") return for keyword in keywords_t: if keyword in answer: freetalking.freetalking() sleep(1) #pygame.play_text("fun_talk.mp3") pygame.play_text("call_me_again.mp3") return pygame.play_text("call_me_again.mp3") return