Skip to main content

OpenSesame Plug-in: Audio Low Latency

An OpenSesame plug-in for playing and recording audio files with low latency.

Copyright, 2022, Bob Rosbag

About

The main goal of this plug-in is to play and record audio with minimal and predictable latencies to achieve a high accuracy and precision. The 'PyAlsaAudio' package which uses the Linux ALSA audio system provided the best results within Python. 'PortAudio' and 'sounddevice' are cross-platform and work on both Windows and Linux.

This plug-in consists of playback and recording items as well as foreground and background (multi-threaded) items. Both playback and recording have their own init item. These should be placed at the beginning of an experiment.

Difference between foreground and background:

  • Foreground items play/record until the file ends or the set duration has passed.
  • Background items consist of a 'start', 'wait' and 'stop' item. These are fully multi-threaded. After the start of the playback/recording, the item will immediately advance to the next item. When it reaches the 'stop' or 'wait' item, it will stop the audio or wait until the file ends or duration has passed.

Seven items for playback:

  • Play Init initialization of the playback audio device, this should be placed at the beginning of an experiment.

Foreground:

  • Play starts the playback of audio, it will play the entire audio file or will stop after the set duration has passed before continuing to the next item in the experiment.

Background:

  • Play Start starts the playback of audio, it will directly advance to the next item in the experiment.

  • Play Wait waits until the thread from 'Play Start' is finished (end of audio or surpassing the duration) before advancing to the next item in the experiment.

  • Play Stop sends a stop signal to the 'Play Start' thread to stop immediately and checks if the thread has finished.

  • Play Pause pauses playback of audio.

  • Play Resume resumes playback of audio.

Seven items for recording:

  • Record Init initialization of the recording audio device, this should be placed at the beginning of an experiment.

Foreground:

  • Record starts the recording of audio, it will record for the set duration before continuing to the next item in the experiment.

Background:

  • Record Start starts the recording of audio, it will directly advance to the next item in the experiment.

  • Record Wait waits until the thread from 'Record Start' is finished (surpassing the duration) before advancing to the next item in the experiment.

  • Record Stop sends a stop signal to the 'Record Start' thread to stop immediately and checks if the thread has finished.

  • Record Pause pauses recording of audio.

  • Record Resume resumes recording of audio.

Variables in the log file ([kind] is play or record):

  • Init items: audio_low_latency_[kind]_module, _device_name, _period_size, _period_time, _period_time_exact, _bitdepth, _samplewidth, _samplerate and _channels; with PyAlsaAudio also _buffer_size, _periods and buffer_time; and audio_low_latency[kind]_soundcard (see below).
  • Play, record and start items: the timestamps time_stimulus_onset_[item_name] and time_stimulus_offset_[item_name] (no offset in dummy mode).
  • Keys: audio_low_latency_[kind]key_presses and audio_low_latency[kind]key_timestamps (play and record items), audio_low_latency[kind]start_key_presses and audio_low_latency[kind]_start_key_timestamps (start items), separated by ';'.
  • Play and play start items: wav_duration and wait_to_finish (in ms; wait_to_finish not in dummy mode).

The sound card (audio_low_latency_[kind]_soundcard) is found as follows:

  • Linux (PyAlsaAudio, and the "(hw:X,Y)" devices of SoundDevice and PyAudio): the codec of an onboard (HD Audio) device, e.g. "Realtek ALC1220", else the name of the card, e.g. "MOTU M2", from /proc/asound. Devices that are not on a sound card, such as "default" with a sound server, "pipewire" or "null", give "unknown".
  • Windows and macOS (SoundDevice and PyAudio): the device name, e.g. "Speakers (Realtek(R) Audio)".
  • In dummy mode: "dummy mode".

Known bugs:

  • Recording with the PyAudio module does not seem to work at the moment

License

This software is distributed under the terms of the GNU General Public License 3. The full license should be included in the file COPYING, or can be obtained from:

This plug-in contains works of others. Icons are derivatives of the Faience icon theme, Faenza icon theme and Papirus icon theme.

Documentation

Installation instructions and documentation on OpenSesame are available on the documentation website:

Metadata

Release files for opensesame-plugin-audio-low-latency 12.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opensesame-plugin-audio-low-latency 12.0.2
File Size Uploaded Provenance
opensesame_plugin_audio_low_latency-12.0.2.tar.gz 106.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for opensesame-plugin-audio-low-latency 12.0.2
File Interpreter ABI Platform
opensesame_plugin_audio_low_latency-12.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 275.3 kB

Release files / opensesame_plugin_audio_low_latency-12.0.2.tar.gz

Download URL opensesame_plugin_audio_low_latency-12.0.2.tar.gz
Size 106.5 kB
Tags Source
SHA-256 checksum
How to use checksums
da29f149962ae61065fc9eb1c1a78a8878af2529657eb655d3219d5ecd57aece
BLAKE2b-256 checksum
How to use checksums
c1aaed50cf52ad19247e8589c43451946cb84805b766dcd4f7cf2c9fedffddf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / opensesame_plugin_audio_low_latency-12.0.2-py3-none-any.whl

Download URL opensesame_plugin_audio_low_latency-12.0.2-py3-none-any.whl
Size 168.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9aa0a6a0cd653fcfc84c7a9ad776cb7ee9b8f5dc4754cc4bcd1a05a99e68889
BLAKE2b-256 checksum
How to use checksums
c741d71ff5aa350cee4d80009a46ea9ff921a89640a596d178a8c0df5567d851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for opensesame-plugin-audio-low-latency 12.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

12.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page