adding in callback for reading chunks

This commit is contained in:
talksik
2023-04-27 14:36:48 -07:00
parent daa3241bf6
commit 7a93c9cf9a
2 changed files with 10 additions and 10 deletions
+9 -6
View File
@@ -23,7 +23,15 @@ class Audio:
channels=RESPEAKER_CHANNELS,
input=True,
input_device_index=RESPEAKER_INDEX,
start=False,)
start=False,
stream_callback=self.readCallback,)
def readCallback(self, out_data, frame_count, time_info, status):
print("reading chunk")
self.frames.append(out_data)
# If len(data) is less than requested frame_count, PyAudio automatically
# assumes the stream is finished, and the stream stops.
return (out_data, pyaudio.paContinue)
def isRecording(self):
return self.recordStream.is_active()
@@ -33,11 +41,6 @@ class Audio:
self.recordStream.start_stream()
self.frames = []
def readChunk(self):
print("reading chunk")
data = self.recordStream.read(CHUNK)
self.frames.append(data)
def stopRecord(self, play=True, save=False):
print("* done recording")
self.recordStream.stop_stream()
+1 -4
View File
@@ -18,15 +18,12 @@ GPIO.setup(BUTTON, GPIO.IN)
audioInstance = audio.Audio()
while True:
if audioInstance.isRecording():
audioInstance.readChunk()
state = GPIO.input(BUTTON)
if state:
print("button: OFF")
if audioInstance.isRecording():
audioInstance.stopRecord()
audioInstance.stopRecord(play=False)
else:
print("button: ON")
if not audioInstance.isRecording():