GithubHelp home page GithubHelp logo

pyreiz / pyreiz Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 1.18 MB

Reiz is a collection of python modules to present visual and auditory stimuli and send markers with LSL

License: MIT License

Python 99.45% Makefile 0.30% Shell 0.25%
pyglet lsl stimulus-presentation stimulus marker labstreaminglayer

pyreiz's Introduction

Reiz

pyReiz is a low-level auditory and visual stimulus presentation suite wrapping pyglet, sending markers via a pylsl outlet. You can also read more extensive documentation online.

DOI MIT license PyPI version Build Status Coverage Status Documentation Status

basic-example

Installation

The requirements for pyReiz are pyglet and pylsl. They are checked, and if necessary installed, during pip install. There is also a dependency on pyttsx3 to allow on-demand synthesis of auditory cues from text. If you don't need that or can't acquire a version of pyttsx3 for your architecture, install pyreiz without the [tts] suffix.

Windows

pip install Reiz[tts]

Linux

The most recent version of pylsl is not yet on pypi. A solution is to install libsl manually. You download a recent build of liblsl from https://github.com/sccn/liblsl/releases. Afterwards, install pylsl directly from github.

pip install git+https://github.com/labstreaminglayer/liblsl-Python.git
pip install Reiz[tts]

Mac

On Mac, tts and reiz-marker are not supported. These functionalities will be mocked, so at least, you can develop on Mac to deploy on Linux or Windows.

pip install Reiz

Development

git clone https://github.com/pyreiz/pyreiz.git
cd pyreiz
pip install -e .[tts]

Test your installation

After you installed Reiz, you can give it a test-run by calling python -m reiz.examples.basic from your terminal. This should start a throwaway MarkerServer, and present a series of visual and auditory stimuli. If anything does not work out, inform us of the issue.

Additional Information

Create your own experiment

Examples can be found in reiz/examples. A quite extensively documented basic example can be found here: basic example.

Recording

Because all markers are send via LSL, i suggest recording with Labrecorder. Use at least 1.13, as this version supports BIDS-conform recording, offers a remote interface and has a critical timing bugfix included.

Requirements

The key requirements for pyReiz are pyglet and pylsl. We require pylsl>=1.13 because a timing issue was fixed in that version (see sccn/liblsl#8), and pyglet>1.4 because there was a breaking change between 1.3 and 1.4 in the way audio was generated and played (see #2). For text-to-speech, which is included with [tts], a key requirement is pyttsx3.

Acknowledgments

I adapted code from Cocos2d for generation of some openGL primitives.

pyreiz's People

Contributors

agricolab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

moan0s nanoonyx

pyreiz's Issues

Error when running reiz-marker

When running reiz-marker, I get the following error messages:

OSError: [WinError -2147417850] Der Threadmodus kann nicht nach dem Einstellen geändert werden

TypeError: category must be a Warning subclass, not 'str'

Playing Message twice in rapid succession on Win10 raises RuntimeError

"""
versions
reiz 0.3.5.0
pyglet 1.5
pylsl 1.13.1
pyttsx3 2.81
"""
import time
import reiz
from reiz.audio import Message

canvas = reiz.Canvas()
canvas.open()

msg = Message('ready')
reiz.Cue(canvas, audiostim = msg).show(msg.duration+0.5)
time.sleep(2)
reiz.Cue(canvas, audiostim = msg).show(msg.duration)

throws the following error

Exception in thread Thread-34:
Traceback (most recent call last):
  File "C:\Users\Messung\AppData\Local\Continuum\anaconda3\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\Messung\AppData\Local\Continuum\anaconda3\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "c:\tools\pyreiz\reiz\_audio\tts.py", line 68, in play_blocking
    self.engine.runAndWait()
  File "C:\Users\Messung\AppData\Local\Continuum\anaconda3\lib\site-packages\pyttsx3\engine.py", line 177, in runAndWait
    raise RuntimeError('run loop already started')
RuntimeError: run loop already started
'''

yet, this snippet works

msg.play_blocking()
time.sleep(1)
msg.play()

Solve dependency issues with pyglet and pyttsx3

The example for reiz was not able to run when reiz was installed freshly. These issues were introduced, as the most recent releases of pyglet and pyttsx3 threw exceptions. Pinning pyglet to 1.5 https://github.com/pyreiz/pyreiz/blob/develop/setup.py#L28 and pyttsx3 tp 2.7 to https://github.com/pyreiz/pyreiz/blob/develop/setup.py#L47 solved this issue for the time being.

Still, there should be intermittent checks to see whether more recent releases of these dependencies run fine again, or to find out whether we need to adapt reiz to be compatible with the dependencies again.

Playing sound with pyglet 1.4

See pyglet/pyglet#81

def play_and_stop(sound):
    t0 = time.time()
    from threading import Timer
    player = sound.play()
    t = Timer(player.source.duration, player.delete)
    t.start()
    return player.source.duration + t0 -time.time()

def play_blocking(sound):
    rest = play_and_stop(sound)
    t0 = time.time()
    while (time.time()-t0) < rest:
        pass
    return 0

rest = play_blocking(get_sound())
print(rest)

rest = play_and_stop(get_sound())
print(rest)

Fast pushing markers slows down reiz

When pushing multiple markes fast after each other, the time it takes for pushing the marker get inconsistent. Sometimes it takes up to 1 sec.

Example code to reproduce the problem

import reiz
import time

for i in range(0,10,1):
    t0 = time.time()
    reiz.marker.push("first")
    print("1: ", time.time()-t0)

Text to speech backend not found on Windows during import of reiz

With Reiz 3.5.1 the following OS Error is thrown while importing reiz.

(studypowerphase) C:\Users\study-power-phase\Desktop\study_power_phase_tms\power_and_phase_tms>python protocol.py
Traceback (most recent call last):
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\study-power-phase\Desktop\study_power_phase_tms\power_and_phase_tms\protocol.py", line 8, in <module>
    import reiz
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\reiz\__init__.py", line 8, in <module>
    import reiz.audio as audio
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\reiz\audio.py", line 76, in <module>
    library = make_library()
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\reiz\audio.py", line 44, in make_library
    lib[name] = Message(**args)
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\reiz\_audio\tts.py", line 35, in __init__
    self.engine = pyttsx3.init()
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\pyttsx3\drivers\sapi5.py", line 1, in <module>
    import comtypes.client  # Importing comtypes.client will make the gen subpackage
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\comtypes\__init__.py", line 160, in <module>
    CoInitializeEx()
  File "C:\Users\study-power-phase\anaconda3\envs\studypowerphase\lib\site-packages\comtypes\__init__.py", line 151, in CoInitializeEx
    _ole32.CoInitializeEx(None, flags)
  File "_ctypes/callproc.c", line 997, in GetResult
OSError: [WinError -2147417850] Der Threadmodus kann nicht nach dem Einstellen geändert werden

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.