getting rid of weird checker for if recording
This commit is contained in:
+9
-7
@@ -18,6 +18,8 @@ class Audio:
|
|||||||
self.frames = []
|
self.frames = []
|
||||||
self.pyaudio = pyaudio.PyAudio()
|
self.pyaudio = pyaudio.PyAudio()
|
||||||
self.recordStream = None
|
self.recordStream = None
|
||||||
|
self.playbackStream = None
|
||||||
|
self._isRecording = False
|
||||||
|
|
||||||
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)
|
||||||
@@ -26,9 +28,7 @@ class Audio:
|
|||||||
return (out_data, pyaudio.paContinue)
|
return (out_data, pyaudio.paContinue)
|
||||||
|
|
||||||
def isRecording(self):
|
def isRecording(self):
|
||||||
if self.recordStream is None:
|
return self._isRecording
|
||||||
return False
|
|
||||||
return self.recordStream.is_active()
|
|
||||||
|
|
||||||
def startRecord(self):
|
def startRecord(self):
|
||||||
print("* recording stream started")
|
print("* recording stream started")
|
||||||
@@ -41,12 +41,14 @@ class Audio:
|
|||||||
start=False,
|
start=False,
|
||||||
stream_callback=self.readCallback,)
|
stream_callback=self.readCallback,)
|
||||||
self.recordStream.start_stream()
|
self.recordStream.start_stream()
|
||||||
|
self._isRecording = True
|
||||||
self.frames = []
|
self.frames = []
|
||||||
|
|
||||||
def stopRecord(self, play=True, save=False):
|
def stopRecord(self, play=True, save=False):
|
||||||
print("* done recording")
|
print("* done recording")
|
||||||
self.recordStream.stop_stream()
|
self.recordStream.stop_stream()
|
||||||
self.recordStream.close()
|
self.recordStream.close()
|
||||||
|
self._isRecording = False
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
self._saveFile()
|
self._saveFile()
|
||||||
@@ -68,7 +70,7 @@ class Audio:
|
|||||||
print("* playing recorded audio")
|
print("* playing recorded audio")
|
||||||
print(len(self.frames))
|
print(len(self.frames))
|
||||||
|
|
||||||
playbackStream = self.pyaudio.open(
|
self.playbackStream = self.pyaudio.open(
|
||||||
format=self.pyaudio.get_format_from_width(RESPEAKER_WIDTH),
|
format=self.pyaudio.get_format_from_width(RESPEAKER_WIDTH),
|
||||||
channels=RESPEAKER_CHANNELS,
|
channels=RESPEAKER_CHANNELS,
|
||||||
rate=RESPEAKER_RATE,
|
rate=RESPEAKER_RATE,
|
||||||
@@ -77,13 +79,13 @@ class Audio:
|
|||||||
|
|
||||||
# loop through self.frames and play audio
|
# loop through self.frames and play audio
|
||||||
for frame in self.frames:
|
for frame in self.frames:
|
||||||
playbackStream.write(frame)
|
self.playbackStream.write(frame)
|
||||||
|
|
||||||
print("* done playing recorded audio")
|
print("* done playing recorded audio")
|
||||||
|
|
||||||
# cleanup stuff
|
# cleanup stuff
|
||||||
playbackStream.stop_stream()
|
self.playbackStream.stop_stream()
|
||||||
playbackStream.close()
|
self.playbackStream.close()
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
self.pyaudio.terminate()
|
self.pyaudio.terminate()
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
# it will then play the audio back to the user from memory
|
# it will then play the audio back to the user from memory
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time
|
|
||||||
|
|
||||||
# importing sys
|
# importing sys
|
||||||
import sys
|
import sys
|
||||||
@@ -27,5 +26,3 @@ while True:
|
|||||||
else:
|
else:
|
||||||
if not audioInstance.isRecording():
|
if not audioInstance.isRecording():
|
||||||
audioInstance.startRecord()
|
audioInstance.startRecord()
|
||||||
|
|
||||||
time.sleep(1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user