open and close in loop
This commit is contained in:
+10
-8
@@ -17,14 +17,6 @@ class Audio:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.frames = []
|
self.frames = []
|
||||||
self.pyaudio = pyaudio.PyAudio()
|
self.pyaudio = pyaudio.PyAudio()
|
||||||
self.recordStream = self.pyaudio.open(
|
|
||||||
rate=RESPEAKER_RATE,
|
|
||||||
format=self.pyaudio.get_format_from_width(RESPEAKER_WIDTH),
|
|
||||||
channels=RESPEAKER_CHANNELS,
|
|
||||||
input=True,
|
|
||||||
input_device_index=RESPEAKER_INDEX,
|
|
||||||
start=False,
|
|
||||||
stream_callback=self.readCallback,)
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -37,12 +29,21 @@ class Audio:
|
|||||||
|
|
||||||
def startRecord(self):
|
def startRecord(self):
|
||||||
print("* recording stream started")
|
print("* recording stream started")
|
||||||
|
self.recordStream = self.pyaudio.open(
|
||||||
|
rate=RESPEAKER_RATE,
|
||||||
|
format=self.pyaudio.get_format_from_width(RESPEAKER_WIDTH),
|
||||||
|
channels=RESPEAKER_CHANNELS,
|
||||||
|
input=True,
|
||||||
|
input_device_index=RESPEAKER_INDEX,
|
||||||
|
start=False,
|
||||||
|
stream_callback=self.readCallback,)
|
||||||
self.recordStream.start_stream()
|
self.recordStream.start_stream()
|
||||||
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()
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
self._saveFile()
|
self._saveFile()
|
||||||
@@ -79,6 +80,7 @@ class Audio:
|
|||||||
|
|
||||||
# cleanup stuff
|
# cleanup stuff
|
||||||
playbackStream.stop_stream()
|
playbackStream.stop_stream()
|
||||||
|
playbackStream.close()
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
self.pyaudio.terminate()
|
self.pyaudio.terminate()
|
||||||
|
|||||||
Reference in New Issue
Block a user