Adjust sound volume individually

Hey everyone,

I’m new to PsychoPy and try to program an experiment that needs to run online, too.
I’ve done most of the experiment in the builder already, but cannot find a solution for a task in the beginning:
The volume of a presented sound should be individually adjusted in a way that it is aversive but not painful. Therefore, I’ve planned the following:

  1. Play a sound at a low volume (e.g. 0.3)
  2. Ask the participant something like “Press right arrow, if the volume of the noise is aversive; press left if it is not aversive yet”
  3. After key press “left”, increase the volume by 0.1
  4. Start over with increased volume
    As soon as the participants press the “right” key (i.e., noise is aversive) I need to save the noise with that specific volume to use it later in the experiment.

This is what I’ve tried so far:

Flow

The first Routine (PlaySound_Code) comprises a code component:

WN = sound.Sound('WhiteNoise1000-16Bit.wav')
Vol = 0.8
increase = 0.1

in the “Begin Experiment” tab;

WN.setVolume(Vol)
WN.play()

in the “Begin Routine" tab;

The feedback Routine includes (1) a text component, asking the participants to press left or right key; (2) a key response component with left and right as allowed keys; (3) another code component (at the top of the Routine) saying:

if Key_press.keys == "left":
    Vol = Vol + increase
elif Key_press.keys == "right": 
    Vol = Vol – increase

In the “Begin Routine” Tab.

I used the “Vol = Vol-increase” line as a control to see what it does. The weird thing is that after a key press the volume is stepwise reduced, but never increased and I really don’t know why…
I was also thinking to add the volume increases as a condition to an Excel file and play it in a loop, but I couldn’t come up with a final solution.
I really would appreciate any help with this, because I couldn’t really find anything similar, expect one explanation of @Becca, were she added the “if-condition” in the “End Routine” tab of the first component, but this doesn’t do anything to the volume at all. (Generating Sound)
Thank you for any advice!

Elena

Hi there,

Does this demo do what you need? https://run.pavlovia.org/lpxrh6/adjustvolume

If so you can download the project here Rebecca Hirst / adjustVolume · GitLab

Hope this helps :slight_smile:

Becca

Hi,

thank you so much for the quick response, this looks great!
I will have a look at it in detail, but I think this is exactly what I was looking for :partying_face:

I might have some other questions later but this helps a lot for now!

Thank you again :slight_smile:

Elena

You are welcome! if this does provide a solution please can you mark the response with “solution” that way future forum users can easily navigate the answer :slight_smile:

Good luck!
Becca

Sure :slight_smile:

Regards, Elena