| Reference | Downloads | Github

Triggering a sound for a heartbeat discrimination task (interoception) with python

Hello, Im very new to python.
Does anyone know how might a voltage input (R-wave) trigger an output of sound with a delay?


The question is underspecified. Do you already have some device in the computer that reads the R wave and you just want to know how to read this device with python and then start a sound file?

1 Like

Hi, Ben,
Very sorry I missed your response.
I have a BIOPAC system that triggers a voltage everytime there is an R wave. So Id like the R-wave, which results in a voltage input to trigger a series of 10 sounds either 100 ms or 500 ms after the input .

What stage are you at? Have you discovered how to get python to ‘know’
when the R wave has happened and your problem is how to link this to
the code for presenting the sounds, or, are you still trying to get the
detection of the R wave figured out?

The BIopac detects the R wave and results in voltage. The problem is how to get the voltage to trigger a series of 10 sound with either 100 ms or 500 ms delay.

thanks very much, Gita

Are you able to get the voltage into python through some kind of read
command or is that the first problem: How can you get the voltage in
to python so you can know when to play the sounds?

Are the sounds in sound files (wav, mp3, ogg etc) or do you want tones
(e.g., 500 Hz for 50ms, then 1000 Hz for 100ms, then …)

Thanks very much Ben…

Yes, that is the first problem - get the voltage into python through some kind of read command

Tones should be 500 ha, the same regardless of delay.

Regards Gita

Ok the 500 Hz tones are easy to do. Depending on which sound system
you use there is usually a way to specify a tone with freq, duration,
etc. See

for an example.

For getting the the voltage into python, I will have to either
experiment with my system, or, do you already have python monitoring
the channel with the heartbeat and you need a way to filter the signal
to find the wave for the trigger or your trouble is earlier than that,
just getting python the communicate with biopac? Sorry to keep asking
questions, but these are very different problems and I want to make
sure I understand which one needs solving first.