Microphone recordings are saved under same file name and overwrite each other

Description of the problem:
My experiment has a microphone component that produces one recording per condition from the csv. In PsychoPy, the audio files with the recordings are named differently because each one has the trial number appended, e.g. “recording_mic_trials_0.wav”. But when I run the experiment online at Pavlovia, all recordings are saved under the same name, something like “participant_project_date_recording_mic.webm” without the trial information. So the later recordings overwrite the earlier ones and when I download the results, I only get the last recording for each participant. Does anyone have an idea how to fix this?

1 Like

In case that someone encounters the same problem, here is how I solved it:
I added a code component to the routine with the microphone component (called mic) and inserted the following JS code under ‘End Routine’:

    var my_tag = 'task-' + task;
    mic.upload({
      tag: my_tag
    });

This uploads the microphone recording a second time to the pavlovia server for each iteration but with my_tag appended to the file name. task is a variable from my conditions file that is different for each iteration, so the recordings don’t overwrite each other.

2 Likes

Hi acp,
I would like to record a naming response on each trial and save it as a wav file online, but struggle to find a working demo. Coud you possibly share a version of your code?

Hi Henning_Holle,
I have attached a PsychoPy experiment with the relevant components and the associated conditions.csv file. I used PsychoPy 2021.2.3. When you run the experiment on Pavlovia in Pilot mode, the recordings will be downloaded instead of being saved online, but when you change to Running mode, they should be saved online.

The default file format seems to be webm and unfortunately changing the file format of the microphone component in the PsychoPy builder does not seem to work when running the experiment online. If you need the wav format, maybe you could just convert the files afterwards.
Alternatively, you could possibly change the javascript code manually. It’s just one line of code but I think you have to insert it again each time you change something in PsychoPy builder or sync with Pavlovia. It also seems that Firefox does not support to record audio in wav format. But if you want to try, you could replace the following section in the .js files that are generated by PsychoPy (mic-demo.js and mic-demo-legacy-browsers.js) and push the changes manually to the Pavlovia Gitlab.

Generated Code:

  mic = new sound.Microphone({
    win : psychoJS.window, 
    name:'mic',
    sampleRateHz : 44100,
    channels : 'auto',
    maxRecordingSize : 24000.0,
    loopback : true,
    policyWhenFull : 'ignore',
  });

Code which sets .wav as file format:

  mic = new sound.Microphone({
    win : psychoJS.window, 
    name:'mic',
    sampleRateHz : 44100,
    format : 'audio/wav',
    channels : 'auto',
    maxRecordingSize : 24000.0,
    loopback : true,
    policyWhenFull : 'ignore',
  });

conditions.csv (10 Bytes)
mic-demo.psyexp (14.9 KB)

2 Likes

Hi acp,
many thanks, the uploading to server works fine now.

On the first couple of trials of the experiment, I want to play back the recorded word to the participant, to make sure that their mike is working as intended and that they have understood the task.

The microphone component is called mic_2
I have added a JS code at the end of the routine
test_recording = mic_2.getRecording()

in the subsequent routine, I then create a sound object and set the name to
$test_recording

But this doesn’t seem to work. Is there a way to play back the recording from a trial? Would you need to first download the recording from the pavlovia server in order for that to work?

Hi Henning_Holle,
good to hear that the uploading is working.

Unfortunately, I don’t know how to play back the recording to the participant directly in the experiment. In my study, I created a download button, so that the participants have the option to download the recording as a .wav file and play it manually:
mic.download("audio.wav")
But that is definitely not the optimal solution.