better ordering

This commit is contained in:
talksik
2023-04-27 15:22:37 -07:00
parent d94f64d2fe
commit b0cafb4d44
2 changed files with 4 additions and 5 deletions
+2 -3
View File
@@ -23,8 +23,6 @@ class Audio:
def readCallback(self, out_data, frame_count, time_info, status): def readCallback(self, out_data, frame_count, time_info, status):
self.frames.append(out_data) 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) return (out_data, pyaudio.paContinue)
def isRecording(self): def isRecording(self):
@@ -32,6 +30,7 @@ class Audio:
def startRecord(self): def startRecord(self):
print("* recording stream started") print("* recording stream started")
self.frames = []
self.recordStream = self.pyaudio.open( self.recordStream = self.pyaudio.open(
rate=RESPEAKER_RATE, rate=RESPEAKER_RATE,
format=self.pyaudio.get_format_from_width(RESPEAKER_WIDTH), format=self.pyaudio.get_format_from_width(RESPEAKER_WIDTH),
@@ -39,10 +38,10 @@ class Audio:
input=True, input=True,
input_device_index=RESPEAKER_INDEX, input_device_index=RESPEAKER_INDEX,
start=False, start=False,
frames_per_buffer=CHUNK,
stream_callback=self.readCallback,) stream_callback=self.readCallback,)
self.recordStream.start_stream() self.recordStream.start_stream()
self._isRecording = True self._isRecording = True
self.frames = []
def stopRecord(self, play=True, save=False): def stopRecord(self, play=True, save=False):
print("* done recording") print("* done recording")
+2 -2
View File
@@ -40,9 +40,9 @@ while True:
if state: if state:
if audioInstance.isRecording(): if audioInstance.isRecording():
audioInstance.stopRecord()
turnOffLED() turnOffLED()
audioInstance.stopRecord()
else: else:
if not audioInstance.isRecording(): if not audioInstance.isRecording():
audioInstance.startRecord()
turnOnLED() turnOnLED()
audioInstance.startRecord()