コード例 #1
0
def thank_screen(screen, nb_sample):
    background = PGBackground(THANK_BACKGROUND_PATH)
    elements = [background]
    while True:
        drawElements(screen, elements)
        events = pygame.event.get()
        for event in events:
            if event.type in [pygame.KEYUP, pygame.MOUSEBUTTONUP]:
                return
        pygame.time.wait(40)
コード例 #2
0
def instruction_screen(screen):
    background = PGBackground(INSTRUCTION_BACKGROUND_PATH)
    button_next = PGEmptyButton(INSTR_NEXT_BUTTON_RECT, absolute=False)

    elements = [background, button_next]
    while True:
        drawElements(screen, elements)
        events = pygame.event.get()
        if button_next.event_check(events) is PGAction.CLICKED:
            return
        for event in events:
            if event.type == pygame.KEYUP and event.key in [
                    pygame.K_ESCAPE, pygame.K_RETURN, pygame.K_SPACE
            ]:
                return
        pygame.time.wait(40)
コード例 #3
0
def recording(screen, channels=4):
    background = PGBackground(RECORDING_BACKGROUND_PATH)
    logo = PGImage(LOGO_PATH, LOGO_RECT, absolute=False)
    logo.visible = False
    text_wait = PGLabel(RECORDING_WAIT_COORD, "Attendez ... (Soyez prêt !)",
                        100)
    text_wait.visible = True

    text_speak = PGLabel(RECORDING_SPEAK_COORD, "Dites LinTo ! ", 100)
    text_speak.visible = False

    elements = [background, logo, text_wait, text_speak]

    drawElements(screen, elements)
    pygame.time.wait(1000)

    params = AudioParams()
    params.channels = channels

    condition = Condition()
    frames = []
    t = threading.Thread(target=record, args=(
        params,
        frames,
        condition,
    ))
    t.start()
    pygame.time.wait(1000)

    logo.visible = True
    text_wait.visible = False
    text_speak.visible = True

    drawElements(screen, elements)
    clock = pygame.time.Clock()
    while condition.state:
        for event in pygame.event.get():
            if event.type in [pygame.MOUSEBUTTONUP, pygame.KEYUP]:
                condition.state = False
                break
        clock.tick(FPS)
    t.join()
    if len(frames) == 0:
        return None
    return b''.join(frames)
コード例 #4
0
def gender_screen(screen):
    background = PGBackground(GENDER_BACKGROUND_PATH)
    button_man = PGEmptyButton(GENDER_MAN_BUTTON_RECT, absolute=False)
    button_woman = PGEmptyButton(GENDER_WOMAN_BUTTON_RECT, absolute=False)

    elements = [background, button_man, button_woman]
    while True:
        drawElements(screen, elements)
        events = pygame.event.get()
        if button_man.event_check(events) is PGAction.CLICKED:
            return True
        if button_woman.event_check(events) is PGAction.CLICKED:
            return False
        for event in events:
            if event.type == pygame.KEYUP:
                if event.key in [pygame.K_RETURN, pygame.K_RIGHT, pygame.K_f]:
                    return False
                if event.key in [pygame.K_LEFT, pygame.K_SPACE, pygame.K_h]:
                    return False
        pygame.time.wait(40)
コード例 #5
0
def start_screen(screen):
    background = PGBackground(START_BACKGROUND_PATH)
    button_start = PGEmptyButton(START_START_BUTTON_RECT, absolute=False)

    elements = [background, button_start]
    escape_counter = 0
    while True:
        drawElements(screen, elements)
        events = pygame.event.get()
        if button_start.event_check(events) is PGAction.CLICKED:
            return
        for event in events:
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_ESCAPE:
                    escape_counter += 1
                    if escape_counter >= 3:
                        exit(0)
                if event.key in [pygame.K_SPACE, pygame.K_RETURN]:
                    return
        pygame.time.wait(40)
コード例 #6
0
def failed_screen(screen):
    background = PGBackground(FAILED_BACKGROUND_PATH)
    button_continue = PGEmptyButton(FAILED_RETRY_BUTTON_RECT, absolute=False)
    button_quit = PGEmptyButton(FAILED_QUIT_BUTTON_RECT, absolute=False)
    elements = [background, button_continue, button_quit]
    drawElements(screen, elements)

    while True:
        events = pygame.event.get()
        if button_continue.event_check(events) is PGAction.CLICKED:
            return True
        if button_quit.event_check(events) is PGAction.CLICKED:
            return False
        for event in events:
            if event.type == pygame.KEYUP:
                if event.key in [pygame.K_ESCAPE]:
                    return False
                if event.key in [pygame.K_RETURN, pygame.K_SPACE, pygame.K_c]:
                    return True
        pygame.time.wait(40)
コード例 #7
0
def confirm_screen(screen, gender):
    background = PGBackground(CONFIRM_BACKGROUND_PATH)
    button_yes = PGEmptyButton(CONFIRM_YES_BUTTON_RECT, absolute=False)
    button_no = PGEmptyButton(CONFIRM_NO_BUTTON_RECT, absolute=False)

    elements = [background, button_yes, button_no]
    while True:
        drawElements(screen, elements)
        events = pygame.event.get()
        if button_yes.event_check(events) is PGAction.CLICKED:
            return True
        if button_no.event_check(events) is PGAction.CLICKED:
            return False
        for event in events:
            if event.type == pygame.KEYUP:
                if event.key in [pygame.K_ESCAPE, pygame.K_n]:
                    return False
                if event.key in [pygame.K_RETURN, pygame.K_SPACE, pygame.K_o]:
                    return True
        pygame.time.wait(40)
コード例 #8
0
def check_screen(screen, folder, gender, buffer, channels=4):
    params = AudioParams()
    params.channels = channels

    background = PGBackground(CHECK_BACKGROUND_PATH)
    button_yes = PGEmptyButton(CHECK_OK_BUTTON_RECT, absolute=False)
    button_no = PGEmptyButton(CHECK_KO_BUTTON_RECT, absolute=False)
    button_replay = PGEmptyButton(CHECK_REPLAY_BUTTON_RECT, absolute=False)

    elements = [background, button_yes, button_no, button_replay]

    drawElements(screen, elements)

    play_audio(buffer, params)

    while True:
        events = pygame.event.get()
        if button_yes.event_check(events) is PGAction.CLICKED:
            save_audio(
                params, os.path.join(folder,
                                     generate_file_name(folder, gender)),
                buffer)
            return True
        if button_no.event_check(events) is PGAction.CLICKED:
            return False
        if button_replay.event_check(events) is PGAction.CLICKED:
            play_audio(buffer, params)

        for event in events:
            if event.type == pygame.KEYUP:
                if event.key in [pygame.K_ESCAPE, pygame.K_n, pygame.K_RIGHT]:
                    return False
                if event.key in [
                        pygame.K_RETURN, pygame.K_SPACE, pygame.K_o,
                        pygame.K_LEFT
                ]:
                    return True
                if event.key in [pygame.K_r, pygame.K_UP]:
                    play_audio(buffer, params)
        pygame.time.wait(40)
コード例 #9
0
def continue_screen(screen, nb_sample):
    background = PGBackground(CONTINUE_BACKGROUND_PATH)
    button_yes = PGEmptyButton(CONTINUE_YES_BUTTON_RECT, absolute=False)
    button_no = PGEmptyButton(CONTINUE_NO_BUTTON_RECT, absolute=False)
    label_counter = PGLabel((0.67, 0.035),
                            text=str(nb_sample),
                            font_size=270,
                            color=(230, 230, 0))

    elements = [background, button_yes, button_no, label_counter]
    while True:
        drawElements(screen, elements)
        events = pygame.event.get()
        if button_yes.event_check(events) is PGAction.CLICKED:
            return True
        if button_no.event_check(events) is PGAction.CLICKED:
            return False
        for event in events:
            if event.type == pygame.KEYUP:
                if event.key in [pygame.K_ESCAPE, pygame.K_n]:
                    return False
                if event.key in [pygame.K_RETURN, pygame.K_SPACE, pygame.K_o]:
                    return True
        pygame.time.wait(40)