Issues repeating an audio file across trials in 2021.2.3

URL of experiment:
https://run.pavlovia.org/naomilee/2021abb
https://gitlab.pavlovia.org/naomilee/2021abb

Description of the problem:
In updating an experiment built in 2020.1.2 to 2021.2.3 (to take advantage of the textBox and Button components!), I am finding that repeating a single audio file across immediately adjacent trials no longer works. (This seems to only happen in one routine, and it happens at random, because the relevant loops over that routine are randomized. Also, repeating the same audio across adjacent trials still works completely fine offline!) Is there something that would prevent the same audio file from being played again too soon after a first play, only online?

Details:
I have 4 randomized loops that use the training_choice routine. A code component (at the beginning of the routine) references the conditions file to set up the name of the sound file, to be referenced in the Sound field of the routine’s audio component. That audio component has a start time of 0.0, with an empty duration, and the Sound is set every repeat.

Screen Shot 2022-01-17 at 1.31.45 AM

As an example, the loop trials_training_4 refers to the conditions file below. The relevant part of the code component references the verbID, verbSuffixID, and voice, and translates that into the correct audio file name with reference to a dictionary defined in a code component set at the beginning of the whole experiment. As you can see, there are only two audio files possibly being referenced within this loop: nika-biceku-laru.mp3 OR nika-bicete-laru.mp3. As a result, it’s quite likely that, in any given loop with 4 repeats, the same file will be asked to play immediately after having just been played. ONLY when this is the case, the second instance (or any subsequent instances, as long as they are all in a row) will not play on Chrome (or Safari).

A particular mystery is why this issue does not seem to affect my trial routine. That is also randomized, also with an audio Sound dependent on the conditions file, also only with two possible Sounds, each of which often ends up played multiple times in a row. But there, the audio plays every time, as desired. The only difference I can discern in the way the code component and audio components are set up, is that the line in the code component that sets the audio file name is nested in an if statement in the affected (training_choice) routine, but not nested in the unaffected (trial) routine. Not sure why that should make a difference.

snippet of code component defining audio file:

if ((routine == "training4")) {
        audio = ((((("stims/audio-mp3s/nika-" + vocabulary[verbID]) + vocabulary[verbSuffixID]) + "-") + voice) + ".mp3");
        fruit = fruitImageID;
}

dictionary in initial code component at the beginning of the experiment:

vocabulary = {"sg": "cha", "du": "po", "pl": "fi", "A": "te", "B": "ku", "carrot": "pem", "pear": "seeg", "lemon": "dite", "cherry": "lun", "beamup": "bice", "throwaway": "pim", "banana": "deet", "apple": "feek"};

example conditions file

routine verbID fruitImageID numberSuffixID verbSuffixID background beam foreground leftImageNumber midImageNumber rightImageNumber corrAnsT2 voice
training4 beamup pear 0 A empty 0-nika-beam 0-laru-phone sg empty du left laru
training4 beamup pear 0 A empty 0-nika-beam 0-laru-phone sg empty pl left laru
training4 beamup pear 0 B empty 0-nika-beam 0-laru-phone du empty sg left laru
training4 beamup pear 0 B empty 0-nika-beam 0-laru-phone pl empty sg left laru
training4 beamup pear 0 A empty 0-nika-beam 0-laru-phone du empty sg right laru
training4 beamup pear 0 A empty 0-nika-beam 0-laru-phone pl empty sg right laru
training4 beamup pear 0 B empty 0-nika-beam 0-laru-phone sg empty du right laru
training4 beamup pear 0 B empty 0-nika-beam 0-laru-phone sg empty pl right laru
![image 690x121](upload://x42GJ7GWwlECqFobGEh7P5OU5SQ.png)

Some ideas I have tried / will try:

  • I believe audio latency preferences / changing audio library won’t have an impact, since the offline version works fine and I’m only running into this online.
  • Perhaps this is some limit from the browser on playing the same audio immediately after playing it once? Though I’ve only tried Chrome and Safari so far, the issue is the same on both browsers. Haven’t dug into how each handles audio yet, but that is one area I might pursue.
  • Could setting a duration possibly help? Checking or unchecking ‘Sync Start with screen’? (It’s currently checked.) Any other aspect of the audio component setting?
  • How about adding a silent sound at the end of each routine, so that identical calls for the same audio file to be played won’t be right next to each other?
  • Is there something else I can put in the code component (under “End routine”) that will help make js happier about playing the same audio twice in a row?

I would greatly appreciate any thoughts!

I tried adding some silence to the end of the sound files because I found it repeated better if the original sound hadn’t finished.

You’re right — if the audio has not finished playing, then subsequent repeats are able to go ahead as planned. This actually revealed that I was wrong in my original post: other routines did have this issue — I was just advancing through repeats so quickly that I always replayed the audio before the first play had finished! The danger of having gone through your own experiment so many times for troubleshooting, I guess… So thank you very very much for the suggestion, @wakecarter !

However, for the relevant routines in my experiment, the trial only advances to the next repeat (which causes the sound to potentially be replayed) dependent on a key response from the participant. Since a participant could take arbitrarily long, in principle, to make that key response, I’d rather not add excessively long silence to the end of every single possible audio file.

Instead, I’ve solved this issue by modifying the idea I had in my original post slightly:

  • How about adding a silent sound at the end of each routine, so that identical calls for the same audio file to be played won’t be right next to each other?

I added silence at the beginning of each routine instead. That is, I added a short silent audio component (0.1 seconds long) to the beginning of the offending routines, and adjusted the start time of the audio component presenting issues by 0.1 second as well. This interleaves the potentially repeating audio component with different audio files, and allows replay to happen even after the audio file has finished playing; (though I am still not sure what the technical source of the issue is,) that solves my issue!

1 Like

I love that solution! It’s much easier than having to have two versions of the same audio file so I can alternate them, which I did in another experiment.