Closed kittymimo closed 4 years ago
Sorry to keep you waiting. I changed the plugin file. Please change the branch of my repository from master to dev and download the plugin file. (If you can't understand this instruction, please let me know)
With the new file, you can specify the trial_ends_after_audio property as follows:
const sound_test = {
type: 'psychophysics',
stimuli: [
{
obj_type: 'sound',
file: xxx,
trial_ends_after_audio: true
}
],
choices: ['y', 'n'],
prompt: 'Press the Y or N key to respond.',
canvas_height: 500
}
The trial_ends_after_audio property can be specified in each stimulus object.
Hi,
Thanks so much for your help with this. I successfully downloaded the plugin file. However, when I add the line trial_ends_after_audio: true
, I get this error: "ReferenceError: Cannot access uninitialized variable." Here is the script I used:
var retroaction = {
type: 'psychophysics',
stimuli: [
{
obj_type: 'image',
file: "img/x.png",
startX:200
},
{
obj_type: 'sound',
file: jsPsych.timelineVariable('phrase'),
trial_ends_after_audio: true
},
{
obj_type: 'image',
file: jsPsych.timelineVariable('bonne_reponse'),
startX: 625
},
],
background_color: "FFFFFF",
choices: jsPsych.NO_KEYS,
on_start: function(retroaction) {
if (jsPsych.data.getLastTrialData().values()[0].accuracy == true) {
retroaction.stimuli[0].file = "img/crochet.png";
}
}
}
Thanks!
Catherine
I'm sorry, but I don't have time to go into detail right now. Please check to see if you are referring to the old file. Then could you clear your browser's cache data?
Thanks for your answer. I tried what you said but I still get the same error. I'll try to find another way to end the trial. Please let me know if you think of something. Thanks again for your help!
Thank you for your reply.
Could you run this program? https://www.hes.kyushu-u.ac.jp/~bunshin/test/trial_ends_after_audio_test.html This is a sample program which uses the trial_ends_after_audio_test property.
Then, could you confirm that line 125 of the new plugin file says the following?
trial_ends_after_audio: {
type: jsPsych.plugins.parameterType.BOOL,
pretty_name: 'Trial ends after audio',
default: false,
description: 'If true, then the trial will end as soon as the audio file finishes playing.'
},
Hi, The program seems to work (it stops after the speech joke), and I confirm that lines 125-130 are correct. Thanks, Catherine
I'm sorry for keeping you wait.
You wrote that you had received the error: "ReferenceError: Cannot access uninitialized variable."
What was the source code of the line with this error?
Was the line trial_ends_after_audio: true
?
Hi,
Thanks again very much for your help, I really appreciate it.
The line is stim.audio.addEventListener('ended', end_trial);
(line 422 in the plugin).
Thanks,
Catherine
Can I see all the source code or access the web page of the experiment?
Of course! Here is my full script:
<!DOCTYPE html>
<html>
<head>
<title>Recherche sur le langage et les émotions</title>
<script src="jspsych-6.1.0/jspsych.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-audio-keyboard-response.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-psychophysics.js"></script>
<script src="stimuli.js"></script>
<link href="jspsych-6.1.0/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
var timeline = [];
var audio = [];
for (var i=0; i<stimuli.length; i++) {
audio.push(stimuli[i].phrase);
}
var images = [];
for (var i=0; i<stimuli.length; i++) {
images.push(stimuli[i].image1);
}
for (var i=0; i<stimuli.length; i++) {
images.push(stimuli[i].image2);
}
for (var i=0; i<stimuli.length; i++) {
images.push(stimuli[i].bonne_reponse);
}
images.push('img/x.png', 'img/crochet.png');
var instructions = {
type: 'html-keyboard-response',
stimulus: 'Instructions'
}
timeline.push(instructions);
var phrase = {
type: 'audio-keyboard-response',
stimulus: jsPsych.timelineVariable('phrase'),
prompt: '<span style="font-size:40px;">+</span>',
choices: jsPsych.NO_KEYS,
trial_ends_after_audio: true
}
var image = {
timeline: [
{
type: 'psychophysics',
stimuli: [
{
obj_type: 'image',
file: jsPsych.timelineVariable('image1'),
startX: 500
},
{
obj_type: 'image',
file: jsPsych.timelineVariable('image2'),
startX: 750
},
],
background_color: "FFFFFF",
choices: [37, 39],
data: {
correct_response: 37,
},
on_finish: function(data) {
var bonne_reponse = false;
if (data.correct_response == data.key_press) {
bonne_reponse = true;
}
data.accuracy = bonne_reponse;
}
}
]
}
var retroaction = {
type: 'psychophysics',
stimuli: [
{
obj_type: 'image',
file: "img/x.png",
startX:200
},
{
obj_type: 'sound',
file: jsPsych.timelineVariable('phrase'),
trial_ends_after_audio: true
},
{
obj_type: 'image',
file: jsPsych.timelineVariable('bonne_reponse'),
startX: 625
},
],
background_color: "FFFFFF",
choices: jsPsych.NO_KEYS,
on_start: function(retroaction) {
if (jsPsych.data.getLastTrialData().values()[0].accuracy == true) {
retroaction.stimuli[0].file = "img/crochet.png";
}
}
}
var procedure = {
timeline: [phrase, image, retroaction],
timeline_variables: stimuli
}
timeline.push(procedure);
var fin = {
type: 'html-keyboard-response',
stimulus: 'Merci!'
}
timeline.push(fin);
jsPsych.init({
timeline: timeline,
preload_audio: audio,
preload_images: images,
use_webaudio: false,
on_finish: function() {
jsPsych.data.displayData();
}
})
</script>
</html>
Do you need anything else?
Is there a reason you set the use_webaudio property to false? I'm not sure if this property is related to the problem or not, but you should set it to true.
This is the sample program where the use_webaudio was set as false.
https://www.hes.kyushu-u.ac.jp/~bunshin/test/trial_ends_after_audio_test_without_webaudio.html
Then, the trial_ends_after_audio property did not work. You need to set the use_webaudio property to true
Hi,
Thanks a lot for your help with this. This is the reason I had use_webaudio
set to false: https://groups.google.com/g/jspsych/c/eth7QtLghvY/m/85lucGueDAAJ. But I tried using GitHub as a web server as they suggested and now everything seems to be working!
Thanks!
Thank you for your reply. The use_webaudio property should be true for precise presentation of stimuli although you have to use a web server.
Yes, I set it to true as I am now using a web server. Thanks!
Hi,
Is there a "trial_ends_after_audio" parameter in the "psychophysics" plugin? If not, could you please help me set the trial duration to the duration of the audio stimulus?
Thanks!
Catherine