複数のデータストリームを同期させるためのラボストリーミングレイヤー(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) # 単純なスペクトログラムをプロット (パワースペクトル密度)追加リソースこのチュートリアルを Jupyter ノートブックとして EMOTIV GitHub からダウンロードするLSL のオンラインドキュメント、GitHub の公式 README ファイルを含む確認してくださいデータ収集のための一つまたは複数のサポートされているデバイスが必要ですEMOTIV のすべてのブレインウェアデバイスは、データストリームの送受信のための LSL 機能を組み込んだ EmotivPRO ソフトウェアに接続されます追加リソース:Emotiv のデバイスを使用して LSL を実行するためのコード、サンプルスクリプト有用な LSL デモの YouTubeSCCN LSL GitHub リポジトリ、すべての関連ライブラリGitHub リポジトリ、サブモジュールとアプリのコレクション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) # 単純なスペクトログラムをプロット (パワースペクトル密度)追加リソースこのチュートリアルを Jupyter ノートブックとして EMOTIV GitHub からダウンロードするLSL のオンラインドキュメント、GitHub の公式 README ファイルを含む確認してくださいデータ収集のための一つまたは複数のサポートされているデバイスが必要ですEMOTIV のすべてのブレインウェアデバイスは、データストリームの送受信のための LSL 機能を組み込んだ EmotivPRO ソフトウェアに接続されます追加リソース:Emotiv のデバイスを使用して LSL を実行するためのコード、サンプルスクリプト有用な LSL デモの YouTubeSCCN LSL GitHub リポジトリ、すべての関連ライブラリGitHub リポジトリ、サブモジュールとアプリのコレクション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) # 単純なスペクトログラムをプロット (パワースペクトル密度)追加リソースこのチュートリアルを Jupyter ノートブックとして EMOTIV GitHub からダウンロードするLSL のオンラインドキュメント、GitHub の公式 README ファイルを含む確認してくださいデータ収集のための一つまたは複数のサポートされているデバイスが必要ですEMOTIV のすべてのブレインウェアデバイスは、データストリームの送受信のための LSL 機能を組み込んだ EmotivPRO ソフトウェアに接続されます追加リソース:Emotiv のデバイスを使用して LSL を実行するためのコード、サンプルスクリプト有用な LSL デモの YouTubeSCCN LSL GitHub リポジトリ、すべての関連ライブラリGitHub リポジトリ、サブモジュールとアプリのコレクションHyPyP 分析パイプライン、ハイパースキャン研究のために

読むのを続ける

神経振動の基本

© 2025 EMOTIV、全著作権所有。

Consent

あなたのプライバシーの選択(クッキー設定)

*免責事項 – EMOTIV製品は、研究用途および個人的な使用のみを目的としています。当社の製品は、EU指令93/42/EECで定義されている医療機器として販売されていません。当社の製品は、病気の診断や治療を目的として設計または意図されていません。

翻訳についての注意:このウェブサイトの非英語版は、あなたの便利のために人工知能を使用して翻訳されています。私たちは正確さを追求していますが、自動翻訳には原文とは異なるエラーやニュアンスが含まれている可能性があります。最も正確な情報については、当サイトの英語版をご参照ください。

© 2025 EMOTIV、全著作権所有。

Consent

あなたのプライバシーの選択(クッキー設定)

*免責事項 – EMOTIV製品は、研究用途および個人的な使用のみを目的としています。当社の製品は、EU指令93/42/EECで定義されている医療機器として販売されていません。当社の製品は、病気の診断や治療を目的として設計または意図されていません。

翻訳についての注意:このウェブサイトの非英語版は、あなたの便利のために人工知能を使用して翻訳されています。私たちは正確さを追求していますが、自動翻訳には原文とは異なるエラーやニュアンスが含まれている可能性があります。最も正確な情報については、当サイトの英語版をご参照ください。

© 2025 EMOTIV、全著作権所有。

Consent

あなたのプライバシーの選択(クッキー設定)

*免責事項 – EMOTIV製品は、研究用途および個人的な使用のみを目的としています。当社の製品は、EU指令93/42/EECで定義されている医療機器として販売されていません。当社の製品は、病気の診断や治療を目的として設計または意図されていません。

翻訳についての注意:このウェブサイトの非英語版は、あなたの便利のために人工知能を使用して翻訳されています。私たちは正確さを追求していますが、自動翻訳には原文とは異なるエラーやニュアンスが含まれている可能性があります。最も正確な情報については、当サイトの英語版をご参照ください。