diff --git a/audio/audio.py b/audio/audio.py index 538cf2d..2fc0c58 100644 --- a/audio/audio.py +++ b/audio/audio.py @@ -23,8 +23,6 @@ class Audio: def readCallback(self, out_data, frame_count, time_info, status): 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): @@ -32,6 +30,7 @@ class Audio: def startRecord(self): print("* recording stream started") + self.frames = [] self.recordStream = self.pyaudio.open( rate=RESPEAKER_RATE, format=self.pyaudio.get_format_from_width(RESPEAKER_WIDTH), @@ -39,10 +38,10 @@ class Audio: input=True, input_device_index=RESPEAKER_INDEX, start=False, + frames_per_buffer=CHUNK, stream_callback=self.readCallback,) self.recordStream.start_stream() self._isRecording = True - self.frames = [] def stopRecord(self, play=True, save=False): print("* done recording") diff --git a/simple_recorder/push_to_record_and_play.py b/simple_recorder/push_to_record_and_play.py index 084d445..a3cedc9 100644 --- a/simple_recorder/push_to_record_and_play.py +++ b/simple_recorder/push_to_record_and_play.py @@ -40,9 +40,9 @@ while True: if state: if audioInstance.isRecording(): - audioInstance.stopRecord() turnOffLED() + audioInstance.stopRecord() else: if not audioInstance.isRecording(): - audioInstance.startRecord() turnOnLED() + audioInstance.startRecord()