Reply To: Implementing test recording

PennController for IBEX Forums Support Implementing test recording Reply To: Implementing test recording

#8101
Jeremy
Keymaster

Hi,

Why don’t you use .print() on the MediaRecorder element and let participants use the interface to freely record and play back? It would save you a lot of coding

Re. looping: you are already using callback on the Button element “Play” so that’s a command you could use (on another button) to implement a loop-like behavior too. Actually you don’t need to, and probably shouldn’t, use callback on the “Play” button itself, because that’s what makes the script go on without waiting for playback to finish

Re. test.clicked: you place it immediately after creating the Button element, so of course the participant won’t have time to click the button in the 0-1ms it takes the script to move from executing the newButton line to executing the .test.clicked line, and so the test will always fail

Putting this all together, here’s the simple way to implement your test:

newTrial( "audio_check" ,
    defaultText.css({"text-align":"center", "margin-bottom":"1em"}).center().print()
    ,
    newText("instr-1", "Before starting...")
    ,
    newMediaRecorder("audiotest1", "audio")
        .log()
        .print()
        .wait()
    ,
    newText("testagain", "If it seems to you that the audio is not clear and/or there is too much background noise...")
    ,
    newText("next", "If the audio seems clear and of good quality, press CONTINUE")
    ,
    newButton("Continue").center().print().wait()
)

If you really want to implement a custom interface, you could do something like this:

newTrial( "audio_check" ,
    defaultText.css({"text-align":"center", "margin-bottom":"1em"}).center().print()
    ,
    defaultButton.center()
    ,
    newText("instr-1", "Before starting...")
    ,
    newButton("trigger", "Do a test recording")
        .callback(
            clear()
            ,
            newMediaRecorder("audiotest1", "audio").log().record()
            ,
            newButton("Stop").print().wait().remove()
            ,
            getMediaRecorder("audiotest1").stop()
            ,
            newButton("Play").print().wait().remove()
            ,
            getMediaRecorder("audiotest1").play().wait("playback")
            ,
            newText("If it seems to you that the audio is not clear and/or there is too much background noise...")
            ,
            newText("If the audio seems clear and of good quality, press CONTINUE")
            ,
            getButton("trigger").print()  // Clicking this will execute the callback sequence again
            ,
            getButton("Continue").print() // Print the button now: clicking it will end the trial (=validate the wait command)
        )
        .print()
    ,
    // This button will only be printed at the end of a test,
    // So the script won't have a chance to move past the wait command until then
    newButton("Continue").css("margin-top","1em").wait()
)

Jeremy