from gpiozero import Button

# check the recording status
def rec():
    global status
    if status == 0:
        record()
    else:
        stop()

# if not recording then record        
def record():
    global status
    print("recording!")
    status = 1

# if recording then stop
def stop():
    global status
    print("stopped!")
    status = 0

button = Button(17)
# recording status (0 = not recording, 1 = recording)
status = 0

# listen for button press
while True:
    button.when_pressed = rec

