PennController for IBEX › Forums › Support › MediaRecorder – filenames using ID
Tagged: file names, MediaRecorder
- This topic has 4 replies, 3 voices, and was last updated 2 years, 5 months ago by dod.
-
AuthorPosts
-
May 29, 2022 at 1:38 am #8215shamimParticipant
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:
newTrial("ID", defaultText.cssContainer({"margin-bottom":"1em"}).center().print() , newText("ID", "IDを半角数字で記入してください。") , newTextInput("input_ID").cssContainer({"margin-bottom":"1em"}).center().print() , newButton("wait", "次へ").center().print() .wait(getTextInput("input_ID").test.text(/^\d+$/) .failure(newText("この項目は必須です").color("red").print())) , newVar("ID") .global().set(getTextInput("input_ID")) ));
Thank you in advance,
ShamimJune 8, 2022 at 12:02 pm #8224JeremyKeymasterHi 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 ofnewMediaRecorder
What you can do is generate and store a unique ID in a javascript variable and reference that variable in
newMediaRecorder
and inlog
, for exampleJeremy
July 8, 2022 at 6:57 am #8266dodParticipantHi 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 newTrial("speakID", newVar("speakID") .settings.global() .set(v =>[...Array(4)].reduce(a=>a+alphanum.charAt(Math.floor(Math.random()*alphanum.length)),'')) , newText("speakID", "") .settings.text(getVar("speakID")) .print(), 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!
Dod
July 8, 2022 at 12:23 pm #8268JeremyKeymasterHi 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 seevariable
in the scope ofTemplate
in some people’s code, but in your case it looks like you are usingrow
instead (as determined byrow =>
, which I assume comes withTemplate
in your code)You could try that instead:
const speakID = [...Array(4)].reduce(a=>a+alphanum.charAt(Math.floor(Math.random()*alphanum.length)),'') newTrial("speakID", 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")
Jeremy
July 8, 2022 at 7:04 pm #8269dodParticipantThank 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! -
AuthorPosts
- You must be logged in to reply to this topic.