From bd04a284d1ec575807ece5a397b8135d403a984d Mon Sep 17 00:00:00 2001 From: yitbrekmata <121774263+yitbrekmata@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:45:23 -0800 Subject: [PATCH] Adding a metronome sound before line each recording --- muselsl/record.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/muselsl/record.py b/muselsl/record.py index 30a41cb..b99398b 100644 --- a/muselsl/record.py +++ b/muselsl/record.py @@ -11,9 +11,11 @@ from .muse import Muse from .constants import LSL_SCAN_TIMEOUT, LSL_EEG_CHUNK, LSL_PPG_CHUNK, LSL_ACC_CHUNK, LSL_GYRO_CHUNK +import time +from time import sleep +import pygame # Records a fixed duration of EEG data from an LSL stream into a CSV file - def record( duration: int, filename=None, @@ -69,13 +71,21 @@ def record( res = [] timestamps = [] markers = [] + blinkOrNot = [] t_init = time() time_correction = inlet.time_correction() last_written_timestamp = None print('Start recording at time t=%.3f' % t_init) print('Time correction: ', time_correction) + + pygame.mixer.init() + metronome_sound = pygame.mixer.Sound('metronome_click.wav') + while (time() - t_init) < duration: try: + metronome_sound.play() + print("Blink now!") + data, timestamp = inlet.pull_chunk( timeout=1.0, max_samples=chunk_length) @@ -83,6 +93,8 @@ def record( res.append(data) timestamps.extend(timestamp) tr = time() + + if inlet_marker: marker, timestamp = inlet_marker.pull_sample(timeout=0.0) if timestamp: @@ -103,8 +115,11 @@ def record( ) last_written_timestamp = timestamps[-1] + except KeyboardInterrupt: break + + time_correction = inlet.time_correction() print("Time correction: ", time_correction)