adding in loop for button press record

This commit is contained in:
talksik
2023-04-27 13:58:56 -07:00
parent 1a1b49a958
commit 6a177cfb61
2 changed files with 38 additions and 8 deletions
+24
View File
@@ -1,2 +1,26 @@
# this program will record audio while the button is pressed
# it will then play the audio back to the user from memory
import audio
import RPi.GPIO as GPIO
BUTTON = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON, GPIO.IN)
audioInstance = audio.Audio()
while True:
state = GPIO.input(BUTTON)
if audioInstance.isRecording():
audioInstance.readChunk()
if state:
print("button: OFF")
if audioInstance.isRecording():
audioInstance.stopRecord()
else:
print("button: ON")
if not audioInstance.isRecording():
audioInstance.startRecord()