-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.html
609 lines (558 loc) · 25.4 KB
/
task.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<!-- <meta name="viewport" content="user-scalable=no"> -->
<script src="https://unpkg.com/jspsych@7.3.4"></script>
<script src="https://unpkg.com/@jspsych/plugin-external-html@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-audio-slider-response@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/extension-record-video@1.1.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-video-response@1.0.2"></script>
<script src="https://unpkg.com/@jspsych/plugin-initialize-camera@2.0.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-slider-response@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-audio-keyboard-response@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-audio-response@1.0.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@1.2.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-audio-button-response@1.2.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-video-button-response@1.2.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-survey-html-form@1.0.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-preload@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-call-function@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-browser-check@1.0.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-fullscreen@2.0.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-initialize-microphone@1.0.3"></script>
<link href="https://unpkg.com/jspsych@7.3.4/css/jspsych.css" rel="stylesheet" type="text/css" />
<script src="https://nyc3.digitaloceanspaces.com/experiments.childlanglab/childlanglabClient.js"></script>
<script src="params.js"></script>
</head>
<body>
</body>
<script>
childlanglabClient.init();
var jsPsych = initJsPsych(
{
show_progress_bar: true,
auto_update_progress_bar: false,
extensions: [
{
type: jsPsychExtensionRecordVideo,
} // You can handle the saved video data here}
],
on_interaction_data_update: function(data) {
console.log(JSON.stringify(data));
jsPsych.data.get().addToLast({browser_event: data});
},
on_finish: function() {
//jsPsych.data.displayData();
window.location = "https://app.prolific.co/submissions/complete?cc=CELMED4M"
}
}
);
var TRIAL_N = 0;
var URL_CONDITION = jsPsych.data.getURLVariable('condition'); // get condition from url \
var CONDITION = get_condition(URL_CONDITION);
var CONDITION_PARAMS = get_params(CONDITION);
var RANDOM_LIST = `list${jsPsych.randomization.randomInt(1,2)}`; // get random list
var ALERT = "If you wish to participate, you must check the box next to the statement 'I agree to participate in this study.'"
var consent = {
type: jsPsychExternalHtml,
url: "consent.html",
cont_btn: "start",
check_fn: function(){
if (document.getElementById('consent_checkbox').checked){
return true
} else {
alert(ALERT);
return false
}
}
};
var browser_check = {
type: jsPsychBrowserCheck
};
const sound_check = {
type: jsPsychAudioButtonResponse,
stimulus: `https://nyc3.digitaloceanspaces.com/stims.childlanglab/shared-variation/jingles_SAX10.mp3`,
choices: [0,1,2,3,4,5],
prompt: "<p>How many notes did you hear?</p>"
}
const loop_sound_check = {
timeline: [sound_check],
loop_function: function(data){
return data.values()[0].response != 4 ? true : false;
}
}
var fullscreen_check = {
type: jsPsychFullscreen,
fullscreen_mode: true
}
var init_microphone = {
timeline: [
{type: jsPsychInitializeMicrophone}
],
conditional_function: function() {
if (CONDITION == 'SICR'){
return true
} else {
return false
}
}
};
var init_camera = {
timeline: [
{
type: jsPsychInitializeCamera,
include_audio: true,
mime_type: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'
}
],
conditional_function: function() {
if (CONDITION == 'SICR'){
return true
} else {
return false
}
}
};
var saveRecording = {
type: jsPsychCallFunction,
async: true,
func: function(done){
const video_url = jsPsych.data.get().last(1).values()[0].video_url;
const trial_index = jsPsych.data.get().last(1).values()[0].trial_index;
var base64Data = '...';
fetch(video_url)
.then(response => {return response.blob()})
.then(blob => {
const reader = new FileReader();
reader.onloadend = function() {
if (reader.result) {
console.log('FileReader result:', reader.result);
if (typeof reader.result === 'string' && reader.result.startsWith('data:')) {
base64Data = reader.result.split(',')[1]; // Extract the base64 string
const recording = childlanglabClient.uploadRecording(base64Data, trial_index )
console.log(recording)
done(recording)
} else {
console.error('Unexpected FileReader result format:', reader.result);
}
} else {
console.error("FileReader result is empty.");
}
};
reader.readAsDataURL(blob); // This is where the Blob is passed to FileReader
})
.catch(error => {
console.error('Error fetching or processing the Blob URL:', error);
});
}
}
function get_condition(condition){
let conditions = ["AFC", "RATING", "SICR"];
let random_condition = conditions[jsPsych.randomization.randomInt(0,2)]
if (condition == 'random'){
return random_condition
} else {
return condition
}
};
function get_params(condition){
console.log(PARAMS.conditions)
console.log(PARAMS.conditions[condition])
return PARAMS.conditions[condition];
}
var get_instructions = function(these_instructions) {
console.log(these_instructions)
var instructions = {
type: jsPsychHtmlButtonResponse,
stimulus: function() {
return `<div style="max-width: 800px; text-align: left"><p>${these_instructions}</p></div>`},
prompt: "<p></p>",
choices: ["Continue"],
button_html: function(){
return [`<button class="jspsych-btn">%choice%</button>`]
}
}
return instructions
};
var thanks = {
type: jsPsychHtmlButtonResponse,
stimulus: `<p><strong>Thank you!<strong></p><p>The experiment is now finished.</p>`,
prompt: "Press the button to complete the experiment.",
choices: ["Completion code"],
button_html: [`<button class="jspsych-btn">%choice%</button>`]
};
var sendData = {
type: jsPsychCallFunction,
async: true,
func: function (done) {
let data = jsPsych.data.get().json();
childlanglabClient.sendData(data);
done("Sent data object to childlanglab-api")
},
};
var fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "+",
choices: "NO_KEYS",
response_ends_trial: false,
trial_duration: 1000
};
var test_rating = {
timeline: [
{
type: jsPsychAudioSliderResponse,
stimulus: "sounds/silence.wav",
labels: ['⛔️ Not at all like a penguin word', 'Definitely a penguin word ✅'],
on_load: function(){
let display_element = document.querySelector('#jspsych-content');
let image = document.createElement('img');
image.src = "images/pingu-wait.png"; // Replace with your actual image URL
image.style.width = '450px';
display_element.prepend(image);
},
response_ends_trial: false,
response_allowed_while_playing: false,
trial_duration: 1000
},
{
type: jsPsychAudioSliderResponse,
stimulus: function(){
let sound = `sounds/${jsPsych.timelineVariable('sound1')}-resampled.wav`
return sound
},
labels: ['⛔️ Not at all like a penguin word', 'Definitely a penguin word ✅'],
on_load: function(){
let display_element = document.querySelector('#jspsych-content');
let image = document.createElement('img');
image.src = "images/pingu-option-blue.png"; // Replace with your actual image URL
image.style.width = '450px';
display_element.prepend(image);
},
response_allowed_while_playing: false,
require_movement: true,
on_finish: function(data){
data.trial_n = TRIAL_N += 1;
data.selected_condition = CONDITION;
data.random_list = RANDOM_LIST;
let proportion_complete = jsPsych.getProgressBarCompleted();
jsPsych.setProgressBar(proportion_complete += 0.01)
// data.choices = this.choices;
// data.button_pressed = this.choices[data.response];
},
data: {
sound1: jsPsych.timelineVariable('sound1'),
category1: jsPsych.timelineVariable('category1'),
phase: "test",
//sound2: jsPsych.timelineVariable('sound2'),
//category2: jsPsych.timelineVariable('category2'),
}
}
],
timeline_variables: PARAMS.conditions.RATING.test[RANDOM_LIST],
repetitions: 1
}
var test_afc = {
timeline: [
{
type: jsPsychHtmlButtonResponse,
stimulus: "",
prompt: '<p>Which option sounds more like a word in the penguin language?</p>',
response_allowed_while_playing: false,
choices: ["images/pingu-wait.png", "images/pingu-wait.png"],
button_html: [
`<button class="jspsych-btn" style="opacity: 0.2"> <img src=%choice% width="600"></button>`,
`<button class="jspsych-btn" style="opacity: 0.2"> <img src=%choice% width="600"></button>`
],
trial_duration: 1000,
trial_ends_after_audio: true,
},
{
type: jsPsychAudioButtonResponse,
stimulus: function(){
let sound = `sounds/${jsPsych.timelineVariable('sound1')}-resampled.wav`
return sound
},
prompt: '<p>Which option sounds more like a word in the penguin language?</p>',
response_allowed_while_playing: false,
choices: ["images/pingu-option-blue.png", "images/pingu-wait.png"],
button_html: [
`<button class="jspsych-btn"> <img src=%choice% width="600"></button>`,
`<button class="jspsych-btn" style="opacity: 0.2"> <img src=%choice% width="600"></button>`
],
trial_ends_after_audio: true,
},
{
type: jsPsychAudioButtonResponse,
stimulus: function(){
let sound = `sounds/${jsPsych.timelineVariable('sound2')}-resampled.wav`
return sound
},
prompt: '<p>Which option sounds more like a word in the penguin language?</p>',
response_allowed_while_playing: false,
choices: ["images/pingu-option-blue.png", "images/pingu-option-purple.png"],
button_html: [
`<button class="jspsych-btn" style="opacity: 0.2"> <img src=%choice% width="600"></button>`,
`<button class="jspsych-btn"> <img src=%choice% width="600"></button>`
],
trial_ends_after_audio: true
},
{
type: jsPsychHtmlButtonResponse,
stimulus: "",
prompt: '<p>Which option sounds more like a word in the penguin language?</p>',
choices: ["images/pingu-option-blue.png", "images/pingu-option-purple.png"],
button_html: [
`<button class="jspsych-btn" > <img src=%choice% width="600"></button>`,
`<button class="jspsych-btn" > <img src=%choice% width="600"></button>`
],
response_ends_trial: true,
on_finish: function(data){
data.trial_n = TRIAL_N += 1;
data.selected_condition = CONDITION;
data.random_list = RANDOM_LIST;
data.choices = this.choices;
data.button_pressed = this.choices[data.response];
data.choice_sound = [jsPsych.timelineVariable('sound1'), jsPsych.timelineVariable('sound2')][data.response];
data.choice_category = [jsPsych.timelineVariable('category1'), jsPsych.timelineVariable('category2')][data.response];
let proportion_complete = jsPsych.getProgressBarCompleted();
jsPsych.setProgressBar(proportion_complete += 0.01)
},
data: {
sound1: jsPsych.timelineVariable('sound1'),
category1: jsPsych.timelineVariable('category1'),
sound2: jsPsych.timelineVariable('sound2'),
category2: jsPsych.timelineVariable('category2'),
phase: "test",
}
},
fixation
],
timeline_variables: PARAMS.conditions.AFC.test[RANDOM_LIST],
repetitions: 1
};
var test_sicr = {
timeline: [
{
type: jsPsychHtmlKeyboardResponse,
stimulus: "",
choices: "NO_KEYS",
trial_duration: 1000,
post_trial_gap: 0,
prompt: '<img src="images/pingu-wait.png" width="600"><br><br><button class="jspsych-btn" disabled>Next</button><br>',
},
{
type: jsPsychAudioKeyboardResponse,
stimulus: function(){
let sound = `sounds/${jsPsych.timelineVariable('sound1')}-resampled.wav`
return sound
},
choices: "NO_KEYS",
response_allowed_while_playing: false,
trial_ends_after_audio: true,
prompt: '<img src="images/pingu-option-blue.png" width="600"><br><br><button class="jspsych-btn" disabled>Next</button>',
post_trial_gap: 0,
},
{
type: jsPsychAudioKeyboardResponse,
stimulus: function(){
let sound = `sounds/${jsPsych.timelineVariable('sound2')}-resampled.wav`
return sound
},
prompt: '<img src="images/pingu-option-blue.png" width="600"><br><br><button class="jspsych-btn" disabled>Next</button>',
response_allowed_while_playing: false,
choices: "NO_KEYS",
trial_ends_after_audio: true,
post_trial_gap: 0
},
{
type: jsPsychAudioKeyboardResponse,
stimulus: function(){
let sound = `sounds/${jsPsych.timelineVariable('sound3')}-resampled.wav`
return sound
},
prompt: '<img src="images/pingu-option-blue.png" width="600"><br><br><button class="jspsych-btn" disabled>Next</button>',
response_allowed_while_playing: false,
choices: "NO_KEYS",
trial_ends_after_audio: true,
post_trial_gap: 0
},
{
type: jsPsychHtmlVideoResponse,
stimulus: '<img src="images/pingu-listens.png" width="600"><p>Say exactly what Pingu said outloud.</p>',
prompt: '<p style="color: red;">Recording</p>',
recording_duration: 15000,
show_done_button: true,
done_button_label: 'Next',
save_video_url:true,
on_finish: function(data){
let proportion_complete = jsPsych.getProgressBarCompleted();
jsPsych.setProgressBar(proportion_complete += 0.01)
data.selected_condition = CONDITION;
data.random_list = RANDOM_LIST;
},
data: {
sound1: jsPsych.timelineVariable('sound1'),
sound2: jsPsych.timelineVariable('sound2'),
sound3: jsPsych.timelineVariable('sound3'),
category1: jsPsych.timelineVariable('category'),
phase: "test",
}
},
saveRecording,
// {
// type: jsPsychHtmlButtonResponse,
// stimulus: '<img src="images/pingu-listens.png" width="600"><br>',
// prompt: '<p>Say exactly what Pingu said when she is ready to listen.</p>',
// choices: ['Next'],
// trial_duration: 15000,
// extensions: [
// {
// type: jsPsychExtensionRecordVideo,
// } // You can handle the saved video data here}
// ],
// on_finish: function(data){
// let proportion_complete = jsPsych.getProgressBarCompleted();
// console.log(proportion_complete);
// jsPsych.setProgressBar(proportion_complete += 0.22677777)
// console.log(data.record_video_data)
// console.log("object", data.record_video_data.base64)
// console.log("split", data.record_video_data.split(',')[1])
// let recording = childlanglabClient.uploadRecording(data.record_video_data, data.trial_index);
// console.log(window)
// //console.log(chunks)
// //console.log(videoBlob)
// }
// },
fixation
],
timeline_variables: PARAMS.conditions.SICR.test[RANDOM_LIST],
repetitions: 1
};
var exposure = {
timeline: [
{ // take a break after each exposure set
type: jsPsychAudioKeyboardResponse,
stimulus: jsPsych.timelineVariable('sound'),
prompt: function() {
return `<video id="pingu" width="100%" height="auto" autoplay muted>
<source src=${jsPsych.timelineVariable('video')} type="video/mp4">
Your browser does not support the video tag.
</video>
<p></p>`
},
choices: " ",
response_ends_trial: false,
trial_ends_after_audio: true,
post_trial_gap: 1000,
},
{ // take a break after each exposure set
type: jsPsychHtmlButtonResponse,
stimulus: "",
prompt: "What was pingu doing in the video you watched?",
choices: function() {
let choices = [jsPsych.timelineVariable('correct'), jsPsych.timelineVariable('foil')];
let shuffled_choices = jsPsych.randomization.shuffle(choices);
return shuffled_choices;
},
button_html: [
`<button class="jspsych-btn"> <img src=%choice% width="400"></button>`,
`<button class="jspsych-btn"> <img src=%choice% width="400"></button>`
],
post_trial_gap: 1000,
on_finish: function(data){
let proportion_complete = jsPsych.getProgressBarCompleted();
console.log(proportion_complete);
jsPsych.setProgressBar(proportion_complete += 0.22677777)
data.selected_condition = CONDITION;
data.random_list = RANDOM_LIST;
data.choices = this.choices;
data.button_pressed = this.choices[data.response];
data.choice_comprehension = this.choices[data.response];
}
}
],
timeline_variables: [
{sound: 'sounds/block-1-stim.mp3', video: 'video/Pingu_Block1.mp4', correct: "images/block-1-comp-c.png", foil: "images/block-1-comp-f.png"},
{sound: 'sounds/block-2-stim.mp3', video: 'video/Pingu_Block2.mp4', correct: "images/block-2-comp-c.png", foil: "images/block-2-comp-f.png"},
{sound: 'sounds/block-3-stim.mp3', video: 'video/Pingu_Block3.mp4', correct: "images/block-3-comp-c.png", foil: "images/block-3-comp-f.png"}
],
repetitions: 1,
randomize_order: false
}
var exit_survey = {
type: jsPsychSurveyHtmlForm,
preamble: function() {
return `
<div style="text-align: left; max-width: 800px">
<h3>Exit survey</h3>
<p>Thank you for participating in our study! Before you go, we have a few final questions.
Please answer honestly. Your compensation will NOT be affected by your answer.</p>
</div>`
},
html: `
<div style="text-align: left; max-width: 800px">
<p>(1) Have you seen Pingu before?</p>
<div >
<label><input type="radio" name="seen_pingu" value="yes" required> yes</label><br>
<label><input type="radio" name="seen_pingu" value="no" required> no</label><br>
<label><input type="radio" name="seen_pingu" value="not sure" required> not sure</label><br>
<p id="error-msg" style="color:red; display:none;" required>Please select an option!</p>
</div>
<p>(2) Have you participated in any experiments with similar sounds or videos in the past 3 months?</p>
<div >
<label><input type="radio" name="similar_experiment" value="yes" required> yes</label><br>
<label><input type="radio" name="similar_experiment" value="no" required> no</label><br>
<label><input type="radio" name="similar_experiment" value="not sure" required> not sure</label><br>
<p id="error-msg" style="color:red; display:none;" required>Please select an option!</p>
</div>
<p>(3) How attentive were you during the experiment?</p>
<div style="display: flex; align-items: center; justify-content: space-between; width: 800px;">
<label style="font-size: 14px;">I was very distracted</label>
<input type="range" name="attention" style="flex: 1; margin: 0 10px;" min="0" max="100">
<label style="font-size: 14px;">I paid close attention the whole time</label>
</div>
</div>
`,
button_label: "Submit",
save_timeline_variables: true
}
var preload = {
type: jsPsychPreload,
audio: PARAMS.preload.audio,
images: PARAMS.preload.images,
videos: PARAMS.preload.videos,
show_detailed_errors: true
}
var get_test = function(condition) {
switch (condition) {
case 'AFC':
return test_afc
case 'RATING':
return test_rating
case 'SICR':
return test_sicr
default:
break;
}
}
var timeline = [
consent,
browser_check,
fullscreen_check,
preload,
loop_sound_check,
get_instructions(CONDITION_PARAMS.instructions.exposure),
exposure,
get_instructions(CONDITION_PARAMS.instructions.test),
init_camera, // this is a conditional function that only runs for SICR
init_microphone,
get_test(CONDITION),
exit_survey,
sendData,
thanks
]
jsPsych.run(timeline);
</script>
</html>