| Reference | Downloads | Github

Sound plays 2 times then crashed in 'each frame' code component, but runs in 'begin routine'

Hi all,

I’m currently building a gambling experiment. At each round, participants bet money using a keypad which I ask them to click with the mouse.

What I would like is for a click sound to play when they press a button. However, I currently have this error.

File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\", line 201, in callback
    dat *= thisSound.volume  # Set the volume block by block
TypeError: unsupported operand type(s) for *=: 'NoneType' and 'float'

In practice, clicking makes the sound play once but the code inside that statement fails to run (doesn’t update their current bet), I can click to run the sound again, but on the third time the sound will run continuously then crash.

What i’ve tried

  1. I’ve tried changing the hardware preferences as in this post: Sounds stop playing after 2/3 stimuli when running the experiment several times .
  2. And i’ve tried editing the code suggested here (Sounddevice backend issue?) but I couldn’t find the line they were suggesting.
  3. I set the volume where I define the sound clip: click = sound.Sound(“click.wav”, volume=1.0)

I have other audio files in a separate routine which work fine. This is either a winSound or lossSound depending if they won/lost the bet. I wondered maybe my error is due to the code being in each frame, which may example the # Set the volume block by block error?

Doesn’t work in each frame (1st routine)

if ((onePad.contains(PadMouse)  and PadMouse.getPressed()[0] == 1)) or (betInput.keys == '1'):
    if int(len(currentBet)) <= 1:
        currentBet = (currentBet + "1");
        betInput.keys =[]

Does work in begin routine (2nd routine)

if correct == 1:

Any advice would be appreciated :slight_smile:


Why would you want to multiply the dat variable with the current volume of your sound?

Apparently at the point of assignment, your dat variable is set to None and you cannot multiply None and the float thisSound.volume.

Not a clue, its just the error that’s being generated by PsychoPy, I haven’t coded it myself. I was hoping someone else might know what it means.

The type error is why I tried to set the volume when I instantiated the variable at the start using:

click = sound.Sound(“click.wav”, volume=1.0)

By it doesn’t seem to work sadly - assuming that its the volume that its trying to work out from “thisSound.volume”.

Could you upload a version of your experiment containing only the part which produces the error?

Sorry for the delay - the experiment appears to work now although I haven’t changed the code at all (strange). May have been other processes in the background, as all I did was restart my laptop(?).

1 Like