Creaky noises when replaying a sound

URL of experiment:

Description of the problem:
I set a button to replay a sound stimuli using the following code in RoutineEachFrame in JS. “sound_2_answer_c” is the name of the sound stimuli.

I used the same method in another experiment and it worked well. However, some creaky noises occurred when I clicked the button in this experiment. If I don’t release the left button of my mouse, the noise will not disappear, and after I release the left button, it stops and the sound stimuli replays. I am not sure if this has anything to do with the loop, because the other experiment where it functions well has no repetition.

if (button_2_c.status === PsychoJS.Status.STARTED) {
      // check whether button_2_c has been pressed
      if (button_2_c.isClicked) {;
        if (!button_2_c.wasClicked) {
          // store time of first click
          // store time clicked until
        } else {
          // update time clicked until;
          button_2_c.timesOff[button_2_c.timesOff.length - 1] = button_2_c.clock.getTime();
        if (!button_2_c.wasClicked) {
        // if button_2_c is still clicked next frame, it is not a new click
        button_2_c.wasClicked = true;
      } else {
        // if button_2_c is clicked next frame, it is a new click
        button_2_c.wasClicked = false
    } else {
      // keep clock at 0 if button_2_c hasn't started / has finished
      // if button_2_c is clicked next frame, it is a new click
      button_2_c.wasClicked = false;

Hi @Bingzi_Yu, thanks for flagging. Is the audio sourced from file or generated on the fly? Please, would it be possible to send me a link to your project, so I can take a closer look? Thanks, x

Sorry for the late reply! I figured out that it was probably because my code served as “play on every frame”, so before I released my mouse button, it would keep playing the sound of the first couple of milliseconds. After I changed the code to realize “play on every click”, the audio became normal.