Description of the problem: In the Pavlovia piloting mode of my experiment, the first routine with a sound component fails to begin. I am receiving the following error:
when setting the duration of the sound
this method is abstract and should not be called.
…which I’ve traced to this part of the source code for the SoundPlayer:
/**
* Set the duration of the sound, in seconds.
*
* @name module:sound.SoundPlayer#setDuration
* @function
* @public
* @abstract
*/
setDuration(duration_s)
{
throw {origin: ‘SoundPlayer.setDuration’, context: ‘when setting the duration of the sound’, error: ‘this method is abstract and should not be called.’};
}
However, I’m not sure what would be causing this. I have no code in that routine that references or calls the setDuration() function. I’ve only set the sound component’s start time to 0.0 sec and its duration to 6.0 sec (to avoid the end of the audio clip from being cut off) from Builder view. The audio clips played in the first loop of this routine are about a second long.
Also included is the Developer JavaScript console view, if helpful.
Well, there’s a counter-intuitive solution : just delete the dutation in “stop” and leave it blank, which in your sound_display properties is “6.0”. it seems that Sound component will stop itself when the audio is over.
I’m also getting the same error when defining the sound duration dynamically. I can’t just remove the duration since I have stimuli that is displayed concurrently with the sound.
I would appreciate the help if someone had the solution to this issue and could help me out! The task URL is
I see that 5eong has a similar problem as I do. Is it possible to answer this here, or should we open a new discussion?
In my experiment, I would also like to vary the duration of the sound file so it is either 1.5 seconds or 0 seconds (i.e., the sound either occurs or does not occur). This works perfectly fine offline in PsychoPy, but when loaded on Pavlovia, I receive the error below:
Unfortunately we encountered the following error:
when setting the duration of the sound
this method is abstract and should not be called.
Try to run the experiment again. If the error persists, contact the experiment designer.
I’m happy to provide more details. Thank you for your help!
I would like to update anyone interested in this topic with what I did. In my experiment, I either wanted the sound to play for 1.5 seconds or not play at all (i.e., play for 0 seconds). Setting the sound duration to 1.5 or 0 in the sound component worked fine offline in PsychoPy, but it did not work online on Pavlovia, as it produced the error in my previous post. There were two solutions that worked:
Make a loop around just the sound routine. In that loop, set “nReps $” to some variable (I called mine “IfSound”). I called an Excel spreadsheet in a different loop outside of this sound loop in the “Conditions” section of the loop, and the Excel spreadsheet contained the “IfSound” parameter. The values here were either 0 or 1. Thus, the sound loop was skipped if there were 0 reps. This solution worked well, except the data output file had issues where it produced separate rows for this loop sometimes, which is not what I wanted.
The better solution for me was to create a code component forcing the routine to end very quickly, and the datafile did not have the row issue as the previous solution.
In the code component under “Begin routine,” I included:
startTime = globalClock.getTime()
In the code component under “Each frame,” I included:
if IfSound == 1:
if globalClock.getTime() - startTime >= 1.5:
continueRoutine = False
elif IfSound == 0:
if globalClock.getTime() - startTime >= 0:
continueRoutine = False
“IfSound” was the same parameter from my Excel spreadsheet as mentioned above. The JS script looked like this:
if ((IfSound === 1)) {
if (((globalClock.getTime() - startTime) >= 1.5)) {
continueRoutine = false;
}
} else {
if ((IfSound === 0)) {
if (((globalClock.getTime() - startTime) >= 0)) {
continueRoutine = false;
}
}
}
Also, for the 0-sec audio trials, the sound file being played was a .wav file of complete silence just to make sure that no sound would play.
It would be much easier if we could set variable durations for sounds, but since we can’t as of this moment (I used PsychoPy version 2020.1.3), this solution was sufficient.
I hope this is helpful to people! Please feel free to reply/comment on this post if there’s more information I can provide.
Yes, I’m having the same problem as @naomileenaomi however when I remove the duration and leave the text box blank as recommended by @fgasking , the current sound file stalls and it never reads the next sound file in. Has anybody figured out any solutions?
NB: This is a problem I’ve been encountering on Pavlovia not when running in PsychoPy.
I’ve had it working where different sounds are played on a different iteration. It sounds like maybe you’re trying to play the next sound before the first sound has finished? Just guessing without seeing your script.
One work around to set a duration for a routine before it loops round again (assuming the sound component is the only component you have), is to set a blank “Text” object with the duration that you want. I’ve had to do this for one or two experiments. Hope this helps.