記憶力に挑戦!Emotivアプリで新しいN-Backゲームをプレイしましょう

複数のデータストリームを同期させるためのラボストリーミングレイヤー(LSL)

ロシニ・ランデニヤ

2025/10/01

共有:

ロシニ・ランデニヤルーカス・クライン

操作:
コマンドラインで実行すると、このスクリプトはすぐにLSLストリームを開始します。'Enter'キーが押されると、トリガーが送信され、オーディオファイルが再生されます。"""

import sounddevice as sd
import soundfile as sf
from pylsl import StreamInfo, StreamOutlet

def wait_for_keypress():
print("音声再生を開始し、LSLマーカーを送信するにはENTERを押してください。")

while True: # This loop waits for a keyboard input
    input_str = input()  # Wait for input from the terminal
    if input_str == "":  # If the enter key is pressed, proceed
        break

def AudioMarker(audio_file, outlet): # 音声を再生し、マーカーを送信するための関数
data, fs = sf.read(audio_file) # オーディオファイルを読み込みます

print("Playing audio and sending LSL marker...")
marker_val = [1]
outlet.push_sample(marker_val) # Send marker indicating the start of audio playback
sd.play(data, fs) # play the audio
sd.wait()  # Wait until audio is done playing
print("Audio playback finished.")

if name == "main": # メインループ
# マーカー用のLSLストリームを設定します
stream_name = 'AudioMarkers'
stream_type = 'Markers'
n_chans = 1
sr = 0 # マーカーは不規則なため、サンプリングレートを0に設定します
chan_format = 'int32'
marker_id = 'uniqueMarkerID12345'

info = StreamInfo(stream_name, stream_type, n_chans, sr, chan_format, marker_id)
outlet = StreamOutlet(info) # create LSL outlet

# Keep the script running and wait for ENTER key to play audio and send marker
while True:
    wait_for_keypress()
    audio_filepath = "/path/to/your/audio_file.wav"  # replace with correct path to your audio file
    AudioMarker(audio_filepath, outlet)
    # After playing audio and sending a marker, the script goes back to waiting for the next keypress</code></pre><p><em><strong>**By running this file (even before playing the audio), you've initiated an LSL stream through an outlet</strong></em><strong>. Now we'll view that stream in LabRecorder</strong></p><p><strong>STEP 5 - Use LabRecorder to view and save all LSL streams</strong></p><ol><li data-preset-tag="p"><p>Open LabRecorder</p></li><li data-preset-tag="p"><p>Press <em><strong>Update</strong></em>. The available LSL streams should be visible in the stream list<br> • You should be able to see streams from both EmotivPROs (usually called "EmotivDataStream") and the marker stream (called "AudioMarkers")</p></li><li data-preset-tag="p"><p>Click <em><strong>Browse</strong></em> to select a location to store data (and set other parameters)</p></li><li data-preset-tag="p"><p>Select all streams and press <em><strong>Record</strong></em> to start recording</p></li><li data-preset-tag="p"><p>Click Stop when you want to end the recording</p></li></ol><p><br></p><img alt="" src="https://framerusercontent.com/images/HFGuJF9ErVu2Jxrgtqt11tl0No.jpg"><h2><strong>Working with the data</strong></h2><p><strong>LabRecorder outputs an XDF file (Extensible Data Format) that contains data from all the streams. XDF files are structured into, </strong><em><strong>streams</strong></em><strong>, each with a different </strong><em><strong>header</strong></em><strong> that describes what it contains (device name, data type, sampling rate, channels, and more). You can use the below codeblock to open your XDF file and display some basic information.</strong></p><pre data-language="JSX"><code>

このサンプルスクリプトは、EmotivPROソフトウェアから収集したEEGデータをインポートおよび注釈するためのいくつかの基本機能を示しています。MNEを使用してXDFファイルを読み込み、基本的なメタデータを印刷し、infoオブジェクトを作成し、パワースペクトルをプロットします。"""

import pyxdf
import mne
import matplotlib.pyplot as plt
import numpy as np

XDFファイルへのパス

data_path = '/path/to/your/xdf_file.xdf'

XDFファイルの読み込み

streams, fileheader = pyxdf.load_xdf(data_path)
print("XDFファイルヘッダー:", fileheader)
print("見つかったストリームの数:", len(streams))

for i, stream in enumerate(streams):
print("\nストリーム", i + 1)
print("ストリーム名:", stream['info']['name'][0])
print("ストリームタイプ:", stream['info']['type'][0])
print("チャンネルの数:", stream['info']['channel_count'][0])
sfreq = float(stream['info']['nominal_srate'][0])
print("サンプリングレート:", sfreq)
print("サンプルの数:", len(stream['time_series']))
print("最初の5データポイントを印刷:", stream['time_series'][:5])

channel_names = [chan['label'][0] for chan in stream['info']['desc'][0]['channels'][0]['channel']]
print("Channel Names:", channel_names)
channel_types = 'eeg'
MNEのinfoオブジェクトを作成

info = mne.create_info(channel_names, sfreq, channel_types)
data = np.array(stream['time_series']).T # データは転置する必要があります:チャンネル x サンプル
raw = mne.io.RawArray(data, info)
raw.plot_psd(fmax=50) # 単純なスペクトログラム(パワースペクトル密度)をプロットします。追加リソースこのチュートリアルをEMOTIV GitHubからJupyterノートブックとしてダウンロードしてください。LSLのオンラインドキュメントを確認し、GitHubの公式READMEファイルを参照してください。データを収集するために、1つ以上のサポートされたデータ収集デバイスが必要です。EMOTIVのすべてのブレインウェアデバイスは、データストリームの送受信のためのLSL機能を搭載しているEmotivPROソフトウェアに接続します。追加リソース:Emotivのデバイスを使用してLSLを実行するためのコード、サンプルスクリプト有用なLSLデモがYouTubeで公開中SCCN LSL GitHubリポジトリ(関連ライブラリが含まれています)サブモジュールとアプリのコレクション用GitHubリポジトリHyperscanning研究のためのHyPyP分析パイプライン

ロシニ・ランデニヤルーカス・クライン

操作:
コマンドラインで実行すると、このスクリプトはすぐにLSLストリームを開始します。'Enter'キーが押されると、トリガーが送信され、オーディオファイルが再生されます。"""

import sounddevice as sd
import soundfile as sf
from pylsl import StreamInfo, StreamOutlet

def wait_for_keypress():
print("音声再生を開始し、LSLマーカーを送信するにはENTERを押してください。")

while True: # This loop waits for a keyboard input
    input_str = input()  # Wait for input from the terminal
    if input_str == "":  # If the enter key is pressed, proceed
        break

def AudioMarker(audio_file, outlet): # 音声を再生し、マーカーを送信するための関数
data, fs = sf.read(audio_file) # オーディオファイルを読み込みます

print("Playing audio and sending LSL marker...")
marker_val = [1]
outlet.push_sample(marker_val) # Send marker indicating the start of audio playback
sd.play(data, fs) # play the audio
sd.wait()  # Wait until audio is done playing
print("Audio playback finished.")

if name == "main": # メインループ
# マーカー用のLSLストリームを設定します
stream_name = 'AudioMarkers'
stream_type = 'Markers'
n_chans = 1
sr = 0 # マーカーは不規則なため、サンプリングレートを0に設定します
chan_format = 'int32'
marker_id = 'uniqueMarkerID12345'

info = StreamInfo(stream_name, stream_type, n_chans, sr, chan_format, marker_id)
outlet = StreamOutlet(info) # create LSL outlet

# Keep the script running and wait for ENTER key to play audio and send marker
while True:
    wait_for_keypress()
    audio_filepath = "/path/to/your/audio_file.wav"  # replace with correct path to your audio file
    AudioMarker(audio_filepath, outlet)
    # After playing audio and sending a marker, the script goes back to waiting for the next keypress</code></pre><p><em><strong>**By running this file (even before playing the audio), you've initiated an LSL stream through an outlet</strong></em><strong>. Now we'll view that stream in LabRecorder</strong></p><p><strong>STEP 5 - Use LabRecorder to view and save all LSL streams</strong></p><ol><li data-preset-tag="p"><p>Open LabRecorder</p></li><li data-preset-tag="p"><p>Press <em><strong>Update</strong></em>. The available LSL streams should be visible in the stream list<br> • You should be able to see streams from both EmotivPROs (usually called "EmotivDataStream") and the marker stream (called "AudioMarkers")</p></li><li data-preset-tag="p"><p>Click <em><strong>Browse</strong></em> to select a location to store data (and set other parameters)</p></li><li data-preset-tag="p"><p>Select all streams and press <em><strong>Record</strong></em> to start recording</p></li><li data-preset-tag="p"><p>Click Stop when you want to end the recording</p></li></ol><p><br></p><img alt="" src="https://framerusercontent.com/images/HFGuJF9ErVu2Jxrgtqt11tl0No.jpg"><h2><strong>Working with the data</strong></h2><p><strong>LabRecorder outputs an XDF file (Extensible Data Format) that contains data from all the streams. XDF files are structured into, </strong><em><strong>streams</strong></em><strong>, each with a different </strong><em><strong>header</strong></em><strong> that describes what it contains (device name, data type, sampling rate, channels, and more). You can use the below codeblock to open your XDF file and display some basic information.</strong></p><pre data-language="JSX"><code>

このサンプルスクリプトは、EmotivPROソフトウェアから収集したEEGデータをインポートおよび注釈するためのいくつかの基本機能を示しています。MNEを使用してXDFファイルを読み込み、基本的なメタデータを印刷し、infoオブジェクトを作成し、パワースペクトルをプロットします。"""

import pyxdf
import mne
import matplotlib.pyplot as plt
import numpy as np

XDFファイルへのパス

data_path = '/path/to/your/xdf_file.xdf'

XDFファイルの読み込み

streams, fileheader = pyxdf.load_xdf(data_path)
print("XDFファイルヘッダー:", fileheader)
print("見つかったストリームの数:", len(streams))

for i, stream in enumerate(streams):
print("\nストリーム", i + 1)
print("ストリーム名:", stream['info']['name'][0])
print("ストリームタイプ:", stream['info']['type'][0])
print("チャンネルの数:", stream['info']['channel_count'][0])
sfreq = float(stream['info']['nominal_srate'][0])
print("サンプリングレート:", sfreq)
print("サンプルの数:", len(stream['time_series']))
print("最初の5データポイントを印刷:", stream['time_series'][:5])

channel_names = [chan['label'][0] for chan in stream['info']['desc'][0]['channels'][0]['channel']]
print("Channel Names:", channel_names)
channel_types = 'eeg'
MNEのinfoオブジェクトを作成

info = mne.create_info(channel_names, sfreq, channel_types)
data = np.array(stream['time_series']).T # データは転置する必要があります:チャンネル x サンプル
raw = mne.io.RawArray(data, info)
raw.plot_psd(fmax=50) # 単純なスペクトログラム(パワースペクトル密度)をプロットします。追加リソースこのチュートリアルをEMOTIV GitHubからJupyterノートブックとしてダウンロードしてください。LSLのオンラインドキュメントを確認し、GitHubの公式READMEファイルを参照してください。データを収集するために、1つ以上のサポートされたデータ収集デバイスが必要です。EMOTIVのすべてのブレインウェアデバイスは、データストリームの送受信のためのLSL機能を搭載しているEmotivPROソフトウェアに接続します。追加リソース:Emotivのデバイスを使用してLSLを実行するためのコード、サンプルスクリプト有用なLSLデモがYouTubeで公開中SCCN LSL GitHubリポジトリ(関連ライブラリが含まれています)サブモジュールとアプリのコレクション用GitHubリポジトリHyperscanning研究のためのHyPyP分析パイプライン

ロシニ・ランデニヤルーカス・クライン

操作:
コマンドラインで実行すると、このスクリプトはすぐにLSLストリームを開始します。'Enter'キーが押されると、トリガーが送信され、オーディオファイルが再生されます。"""

import sounddevice as sd
import soundfile as sf
from pylsl import StreamInfo, StreamOutlet

def wait_for_keypress():
print("音声再生を開始し、LSLマーカーを送信するにはENTERを押してください。")

while True: # This loop waits for a keyboard input
    input_str = input()  # Wait for input from the terminal
    if input_str == "":  # If the enter key is pressed, proceed
        break

def AudioMarker(audio_file, outlet): # 音声を再生し、マーカーを送信するための関数
data, fs = sf.read(audio_file) # オーディオファイルを読み込みます

print("Playing audio and sending LSL marker...")
marker_val = [1]
outlet.push_sample(marker_val) # Send marker indicating the start of audio playback
sd.play(data, fs) # play the audio
sd.wait()  # Wait until audio is done playing
print("Audio playback finished.")

if name == "main": # メインループ
# マーカー用のLSLストリームを設定します
stream_name = 'AudioMarkers'
stream_type = 'Markers'
n_chans = 1
sr = 0 # マーカーは不規則なため、サンプリングレートを0に設定します
chan_format = 'int32'
marker_id = 'uniqueMarkerID12345'

info = StreamInfo(stream_name, stream_type, n_chans, sr, chan_format, marker_id)
outlet = StreamOutlet(info) # create LSL outlet

# Keep the script running and wait for ENTER key to play audio and send marker
while True:
    wait_for_keypress()
    audio_filepath = "/path/to/your/audio_file.wav"  # replace with correct path to your audio file
    AudioMarker(audio_filepath, outlet)
    # After playing audio and sending a marker, the script goes back to waiting for the next keypress</code></pre><p><em><strong>**By running this file (even before playing the audio), you've initiated an LSL stream through an outlet</strong></em><strong>. Now we'll view that stream in LabRecorder</strong></p><p><strong>STEP 5 - Use LabRecorder to view and save all LSL streams</strong></p><ol><li data-preset-tag="p"><p>Open LabRecorder</p></li><li data-preset-tag="p"><p>Press <em><strong>Update</strong></em>. The available LSL streams should be visible in the stream list<br> • You should be able to see streams from both EmotivPROs (usually called "EmotivDataStream") and the marker stream (called "AudioMarkers")</p></li><li data-preset-tag="p"><p>Click <em><strong>Browse</strong></em> to select a location to store data (and set other parameters)</p></li><li data-preset-tag="p"><p>Select all streams and press <em><strong>Record</strong></em> to start recording</p></li><li data-preset-tag="p"><p>Click Stop when you want to end the recording</p></li></ol><p><br></p><img alt="" src="https://framerusercontent.com/images/HFGuJF9ErVu2Jxrgtqt11tl0No.jpg"><h2><strong>Working with the data</strong></h2><p><strong>LabRecorder outputs an XDF file (Extensible Data Format) that contains data from all the streams. XDF files are structured into, </strong><em><strong>streams</strong></em><strong>, each with a different </strong><em><strong>header</strong></em><strong> that describes what it contains (device name, data type, sampling rate, channels, and more). You can use the below codeblock to open your XDF file and display some basic information.</strong></p><pre data-language="JSX"><code>

このサンプルスクリプトは、EmotivPROソフトウェアから収集したEEGデータをインポートおよび注釈するためのいくつかの基本機能を示しています。MNEを使用してXDFファイルを読み込み、基本的なメタデータを印刷し、infoオブジェクトを作成し、パワースペクトルをプロットします。"""

import pyxdf
import mne
import matplotlib.pyplot as plt
import numpy as np

XDFファイルへのパス

data_path = '/path/to/your/xdf_file.xdf'

XDFファイルの読み込み

streams, fileheader = pyxdf.load_xdf(data_path)
print("XDFファイルヘッダー:", fileheader)
print("見つかったストリームの数:", len(streams))

for i, stream in enumerate(streams):
print("\nストリーム", i + 1)
print("ストリーム名:", stream['info']['name'][0])
print("ストリームタイプ:", stream['info']['type'][0])
print("チャンネルの数:", stream['info']['channel_count'][0])
sfreq = float(stream['info']['nominal_srate'][0])
print("サンプリングレート:", sfreq)
print("サンプルの数:", len(stream['time_series']))
print("最初の5データポイントを印刷:", stream['time_series'][:5])

channel_names = [chan['label'][0] for chan in stream['info']['desc'][0]['channels'][0]['channel']]
print("Channel Names:", channel_names)
channel_types = 'eeg'
MNEのinfoオブジェクトを作成

info = mne.create_info(channel_names, sfreq, channel_types)
data = np.array(stream['time_series']).T # データは転置する必要があります:チャンネル x サンプル
raw = mne.io.RawArray(data, info)
raw.plot_psd(fmax=50) # 単純なスペクトログラム(パワースペクトル密度)をプロットします。追加リソースこのチュートリアルをEMOTIV GitHubからJupyterノートブックとしてダウンロードしてください。LSLのオンラインドキュメントを確認し、GitHubの公式READMEファイルを参照してください。データを収集するために、1つ以上のサポートされたデータ収集デバイスが必要です。EMOTIVのすべてのブレインウェアデバイスは、データストリームの送受信のためのLSL機能を搭載しているEmotivPROソフトウェアに接続します。追加リソース:Emotivのデバイスを使用してLSLを実行するためのコード、サンプルスクリプト有用なLSLデモがYouTubeで公開中SCCN LSL GitHubリポジトリ(関連ライブラリが含まれています)サブモジュールとアプリのコレクション用GitHubリポジトリHyperscanning研究のためのHyPyP分析パイプライン

読むのを続ける

神経振動の基本