Real-Time EEG Streaming¶
Coming Soon
Real-time EEG streaming via Lab Streaming Layer (LSL) is planned for a future release. The API is designed but not yet implemented.
Installation¶
This adds pylsl for Lab Streaming Layer protocol support.
Planned API¶
The real-time API will allow continuous TC scoring from a live EEG stream:
from aime_loc import LOC
from aime_loc.eeg import EEG
loc = LOC()
eeg = EEG(loc)
# Connect to LSL stream
stream = eeg.stream(source="lsl", buffer_sec=2.0)
# Real-time scoring loop
for epoch in stream:
profile = eeg.score(epoch)
print(f"TC: {profile.tc_score:.1f}%")
Architecture¶
EEG Device → LSL Stream → Buffer (2s) → PSD → WebSocket API → TC Score
↑
Server-side scoring
(<200ms latency)
Key design:
- Buffer: Collects 2-second windows from LSL stream
- Local PSD: Welch PSD computed locally (same as offline)
- WebSocket: Low-latency scoring via
WS /v1/eeg/streamendpoint - Latency: Target <200ms end-to-end (PSD computation + API round-trip)
Use Cases¶
- Neurofeedback: Real-time TC feedback during meditation or cognitive training
- BCI Research: Cognitive state monitoring for brain-computer interfaces
- Clinical Monitoring: Continuous consciousness assessment
Workaround: Near-Real-Time with Offline Pipeline¶
Until the real-time API is available, you can approximate near-real-time scoring using short recordings:
import time
while True:
# Record 5 seconds of data (via your device's SDK)
data = record_from_device(duration=5.0, sfreq=256)
# Score immediately
recording = eeg.load(data, sfreq=256, device="muse")
recording.preprocess()
epochs = recording.extract_epochs(duration=2.0)
profile = eeg.score(epochs)
print(f"TC: {profile.tc_score:.1f}%")
time.sleep(5)
Next Steps¶
- EEG Quick Start — Offline pipeline (available now)
- Consumer Devices — Device setup guides