Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a metronome sound before line each recording #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion muselsl/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -69,20 +71,30 @@ 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)

if timestamp:
res.append(data)
timestamps.extend(timestamp)
tr = time()


if inlet_marker:
marker, timestamp = inlet_marker.pull_sample(timeout=0.0)
if timestamp:
Expand All @@ -103,8 +115,11 @@ def record(
)
last_written_timestamp = timestamps[-1]


except KeyboardInterrupt:
break



time_correction = inlet.time_correction()
print("Time correction: ", time_correction)
Expand Down