Overwritten audio output files

OS (e.g. Win10): Ubuntu 18.04.3
PsychoPy version (e.g. 1.84.x): 3.2
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?: I am trying to collect participants answers on their auditory imagery experience using rating scales after listening to melodies (.wav files). There are 2 runs of 10 trials each, and in each run only 5 trials should contain the rating scale. For the other 5 there is no time for imagine. So in total there must be 10 recordings in each experiment (no repetition is allowed!). 20 .wav files in total.
However, something must be missing because some stimuli are being repeated and for this reason the output files are being overwritten.

What did you try to make it work?: Not sure what to do. Should be something with the loop commands, but I don’t know what to do next. help!

So, the component code in the tab “End of routine” was:

import sounddevice as sd
import soundfile as sf

from random import choice

filename2 = [
‘Melodias/a01.wav’,
‘Melodias/a03.wav’,
‘Melodias/b02.wav’,
‘Melodias/b03.wav’,
‘Melodias/b04.wav’,
‘Melodias/c03.wav’,
‘Melodias/c04.wav’,
‘Melodias/d04.wav’,
‘Melodias/d05.wav’,
‘Melodias/e05.wav’,
‘Melodias/e06.wav’,
‘Melodias/f06.wav’,
‘Melodias/g07.wav’,
‘Melodias/g08.wav’,
‘Melodias/h08.wav’,
‘Melodias/h09.wav’,
‘Melodias/i09.wav’,
‘Melodias/i10.wav’,
‘Melodias/j10.wav’,
‘Melodias/j11.wav’,
‘Melodias/k11.wav’,
‘Melodias/k12.wav’,
‘Melodias/l12.wav’,
‘Melodias/l13.wav’]
file2 = choice(filename2)

Extract data and sampling rate from file

data2, fs = sf.read(file2, dtype=‘float32’)
sd.play(data2, fs)
status = sd.wait() # Wait until file is done playing

But, in this way some files are played twice sometimes, what makes the program overwrite the output file.

Then, I tried to change to python function:

import sounddevice as sd
import soundfile as sf

import random

filename1 = [
‘Melodias/a01.wav’,
‘Melodias/a03.wav’,
‘Melodias/b02.wav’,
‘Melodias/b03.wav’,
‘Melodias/b04.wav’,
‘Melodias/c03.wav’,
‘Melodias/c04.wav’,
‘Melodias/d04.wav’,
‘Melodias/d05.wav’,
‘Melodias/e05.wav’,
‘Melodias/e06.wav’,
‘Melodias/f06.wav’,
‘Melodias/g07.wav’,
‘Melodias/g08.wav’,
‘Melodias/h08.wav’,
‘Melodias/h09.wav’,
‘Melodias/i09.wav’,
‘Melodias/i10.wav’,
‘Melodias/j10.wav’,
‘Melodias/j11.wav’,
‘Melodias/k11.wav’,
‘Melodias/k12.wav’,
‘Melodias/l12.wav’,
‘Melodias/l13.wav’]
file1 = random.sample(filename1, 1)

Extract data and sampling rate from file

data1, fs = sf.read(file1, dtype=‘float32’)
sd.play(data1, fs)
status = sd.wait() # Wait until file is done playing

But now it doesn’t find the .wav input file and it crashes…