Audio file naming

PennController for IBEX Forums Support Audio file naming

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9715
    Rebecca
    Participant

    Hi,

    I am working on an experiment which involves participants speaking sentences out loud into their computer’s microphone. Each trial creates an individual audio file, which are all uploaded to an external server in a zip file. Participants must also enter an ID at the beginning of the experiment. I have seen that the zip file name is automatically generated and unique, but I am wondering if there is a way to rename the individual audio files based on the ID from the beginning of the experiment. I also see that this is possible if the ID was in the URL, but this experiment involves a text input for the ID.

    I have the following sequences:

    PennController("id",
    
    newText("<p>Please enter your Participant ID and then click the button below to start the experiment.</p>")
    .print()
    ,
    newTextInput("input_ID")
            .cssContainer({"margin-bottom":"1em"})
            .center()
            .print()
    ,
    newButton("Continue")
        .print()
        .wait()
    ,
    newVar("ID")
    .global()
    .set(getTextInput("input_ID"))
    )
    .log( "ID" , getVar("ID") )
    
    PennController.Template( "exp5.csv" ,
        variable => PennController( "exp5Task" ,
        
           [...]
    
            newMediaRecorder(variable.Item+"_"+getVar("ID"),"audio")
                .record()
    [...])

    But this returns audio files with names in the form Item_[object Object].webm. Is there a way to have the entered Participant ID in place of [object Object] in the .webm names?

    Thanks!

    #9717
    Jeremy
    Keymaster

    Hi,

    This is because PennController elements are created immediately, but PennController commands are delayed: getVar() does not return a string, it returns an object that some PennController commands will use to retrieve its value

    What you can do is generate a unique ID for each participant and use it both in the Audio elements’ names and in a log command on the newTrial()s so you can cross-reference things from the results file, for instance:

    uniqueID = [1,2,3,4].map(v=>Math.floor((1+Math.random())*0x10000).toString(16).substring(1)).join('-');
    
    Template( "exp5.csv" , row => 
      newTrial( "exp5Task" ,
        // ...
        newMediaRecorder(uniqueID+"_"+getVar("ID"),"audio").record()
        // ...
      )
      .log("uniqueID", uniqueID)
    )

    Jeremy

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