MediaRecorder – filenames using ID

PennController for IBEX Forums Support MediaRecorder – filenames using ID

  • This topic has 4 replies, 3 voices, and was last updated 2 years ago by dod.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #8215

    I’m going to collect participants’ speech productions with MediaRecorder and have a question about naming audio files using their ID, which is already assigned.

    I would like to name each audio file starting with their ID as follows:
    newMediaRecorder( ID +”-t1-M-“+variable.speaker+”-“+variable.word, “audio”).log().record()

    I know about GetURLParameter(“id”) function, but I am wondering if there is a way to use the ID that my participants write at the beginning of the task as follows:

        newText("ID", "IDを半角数字で記入してください。")
        newButton("wait", "次へ").center().print()

    Thank you in advance,


    Hi Shamim,

    This won’t be possible, because new* PennController commands are executed immediately, that is, before participants can interact with the page. So it’s not possible to reference a value to be set later (the participant’s ID) in the arguments of newMediaRecorder

    What you can do is generate and store a unique ID in a javascript variable and reference that variable in newMediaRecorder and in log, for example



    Hi Jeremy,

    I was trying to store a unique participantID in the audio filename as well.
    I created a javascript variable and referred to it in the newMediaRecorder name, but I always get errors – either “[12:25:57] Uncaught SyntaxError: Unexpected token ‘variable’ (newTrial: 0), or an “ERROR: Wrong number of arguments (or bad argument) to SepWith” (even if I’m not touching the sepWith trials).
    I’m quite sure there is something wrong in the way I refer to the variable in the newMediaRecorder name. But I cannot figure out how to fix it. Could you help me out?

    Here’s the trial with the function to define the variable

    // Set unique participant ID to better recognize audios
            .set(v =>[...Array(4)].reduce(a=>a+alphanum.charAt(Math.floor(Math.random()*alphanum.length)),''))
        newText("speakID", "")
        newButton().print().wait()   // to be deleted, just to double check that the code matches the audiofile
        .log("speakID", getVar("speakID"))

    And here’s the way I named my newMediaRecorder element in following trials
    newMediaRecorder(row.itemID+"_"+row.modality+"_"+variable.speakID, "audio")

    If I don’t refer to the variable in the audiofile name, everything goes smoothly.

    Thank you in advance!



    Hi Dod,

    PennController Var elements are not javascript variables (visit the link in my message above to read about differences between PennController and plain javascript)

    The keyword variable has no meaning in plain javascript, and PennController defines no global object with that name. You will sometimes see variable in the scope of Template in some people’s code, but in your case it looks like you are using row instead (as determined by row =>, which I assume comes with Template in your code)

    You could try that instead:

    const speakID = [...Array(4)].reduce(a=>a+alphanum.charAt(Math.floor(Math.random()*alphanum.length)),'')
        newText("speakID", speakID).print()
        newButton().print().wait()   // to be deleted, just to double check that the code matches the audiofile
    .log("speakID", speakID)
    // ...
    newMediaRecorder(row.itemID+"_"+row.modality+"_"+speakID, "audio")



    Thank you! I realized a bit after posting that I had got your first message completely wrong. So eventually I declared it at the beginning of the script but I just messed things up ( I used var speakID = function randomString() {..., and I decided to get rid of the trial (and the log). And as a result, I was getting a “No Var element named “speakID” found” error that was driving me crazy.)
    Now I can see the logic, and it works perfectly!
    Thank you again!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.