from pylsl import StreamInlet, resolve_stream
import pygame
# first resolve an EEG stream on the lab network
streams = resolve_stream('type', 'EEG')
# create a new inlet to read from the stream
inlet = StreamInlet(streams[0])
# Pygame setup
pygame.init()
size = width, height = 320, 240
screen = pygame.display.set_mode(size)
samples = []
while True:
# get a new sample (you can also omit the timestamp part if you're not
# interested in it)
# Get a sample from the inlet stream
sample, timestamp = inlet.pull_sample()
samples.push(sample)
#TODO: interpolate streamed samples and update game objects accordingly.
# You'll probably need to keep a few samples to interpolate this data.
#TODO: draw game
...
pygame.display.flip()
2条答案
按热度按时间flvlnr441#
Python中有一个LSL模块,叫做pylsl。您应该能够将其纳入您的游戏循环。
以下代码改编自this example:
pftdvrlh2#
增加另一种可能性:来自日内瓦生物技术学院的工程师们已经使用LSL创建了一个库,用于使用EEG的在线范例,称为
NeuroDecode
。它依赖于pylsl
并提供了更高级别的实现。在我的fork版本中,我放弃了(旧的)解码功能,支持对低级功能的改进,例如。信号采集/可视化。
https://github.com/mscheltienne/NeuroDecode