mirror of
https://github.com/chidiwilliams/buzz.git
synced 2026-03-14 14:45:46 +01:00
Fix for errors in test
This commit is contained in:
parent
e6921a5734
commit
069da6c662
1 changed files with 5 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ class RecordingAmplitudeListener(QObject):
|
|||
self.input_device_index = input_device_index
|
||||
self.buffer = np.ndarray([], dtype=np.float32)
|
||||
self.accumulation_size = 0
|
||||
self._active = False
|
||||
|
||||
def start_recording(self):
|
||||
try:
|
||||
|
|
@ -33,16 +34,20 @@ class RecordingAmplitudeListener(QObject):
|
|||
)
|
||||
self.stream.start()
|
||||
self.accumulation_size = int(self.stream.samplerate * self.ACCUMULATION_SECONDS)
|
||||
self._active = True
|
||||
except Exception as e:
|
||||
self.stop_recording()
|
||||
logging.exception("Failed to start audio stream on device %s: %s", self.input_device_index, e)
|
||||
|
||||
def stop_recording(self):
|
||||
self._active = False
|
||||
if self.stream is not None:
|
||||
self.stream.stop()
|
||||
self.stream.close()
|
||||
|
||||
def stream_callback(self, in_data: np.ndarray, frame_count, time_info, status):
|
||||
if not self._active:
|
||||
return
|
||||
chunk = in_data.ravel()
|
||||
self.amplitude_changed.emit(float(np.sqrt(np.mean(chunk**2))))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue