| Reference | Downloads | Github

Semantic file naming for recordings

Recordings are automatically saved in the ‘data’ folder with a filename ‘microphoneComponentName-UnixTime’.
I can work back from the timestamp to the order of the recordings, to which stimulus was playing at the time, provided I don’t randomise my stimuli.

But I’d much rather save the recordings with filenames which reflect the stimuli names in the first place.

Is there a way of doing this from the Builder? (v1.83.04 on Windows) Something like $mic.Filename = $mic.Name+$stimuli?


In Builder’s Experiment Settings you can set the filename/path to a custom value. By default it is:

u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])

which is equivalent to:


You can find out about how to use Python “Formatted strings” here: 5. Built-in Types — Python 2.7.18 documentation

or using a newer alternative format here:

To find out what variables are available to use in the name compile the script from you experiment and scroll down to where the filename variable is defined. Everything above there is available to you.

Apologies, to clarify: Jon’s answer allows me to set a folder name for each run of the experiment. My problem is setting the names of the individual .wav files generated by the microphone component.

Looking at the code, I think you can change the filename in this line:

mic_trial = microphone.AdvAudioCapture(name=‘mic_trial’, saveDir=wavDirName, stereo=True)
by putting “filename=$stimulus” in the constructor.

Looking at the Microphone documentation, I don’t think there is a way of doing this from Builder?

Ah, I see. You’re right - there isn’t a way to specify mic filenames in Builder at the moment but as usual I think a very small Code Component will rescue you; you just need to check out where the bits of code are being inserted.

microphone.AdvAudioCapture has a method setFile():
so you could manually call that using code immediately after you mic is created. To do that you just need a Code Component created immediately after your mic_1 (i.e. in the Builder view it has to come below your Mic Component) and set the Begin Routine to be:


The comments above about constructing that string still stand

Disclosure: I didn’t write the AdvAudioCapture so I might well be wrong :wink: