Fix for errors in test

This commit is contained in:
Raivis Dejus 2026-03-07 06:01:21 +02:00
commit 069da6c662

View file

@ -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))))