PennController for IBEX › Forums › Support › Audioupload
Tagged: InitiateRecorder, MediaRecorder, PHP, UploadRecordings
- This topic has 11 replies, 2 voices, and was last updated 1 year, 4 months ago by Jeremy.
February 2, 2022 at 10:08 am #7708
and once again, I come to you to ask for some help:
In a new experiment, our participants are supposed to audio-record themselves via MediaRecorder. I was able to make the recorder work and at the moment our issue is with the automated audio upload. From the documentation, I understand that we have to use InitiateRecorder to specify a URL for the upload and UploadRecordings to, well, upload the recordings. It also says to use a PHP file and this is where I’m struggling – I know how to create one in the directory, but I do not know how it works or what it needs to have to function (currently it’s just an empty file with all possible permissions).
The current ErrorMessage from the debugger is “MediaRecorder’s Ajax Post failed;could not GET [link]”. I’m adding some code below that I deemed relevant to this.
If you’re able to help out again, this would be greatly appreciated, so thanks a lot in advance! 🙂
PennController.ResetPrefix(null); PennController.AddHost("https://amor.cms.hu-berlin.de/~anamjoya/phonologie/stimuli/"); Sequence("Einverständnis","Recorder","Code","Probedurchlauf",randomize("Item"),"Upload","Meta") , InitiateRecorder("https://amor.cms.hu-berlin.de/~anamjoya/phonologie/audiorecordings/audiorecordings.php","Bevor das Experiment beginnen kann, gewähren Sie nun bitte dem Programm per Klick auf den Link Zugriff auf Ihr Mikrofon.") .label("Recorder") , UploadRecordings("Upload","noblock") [...] newTrial("Item", [...] newButton("start recording","start recording") .center() .print() .wait() .remove() , newText("Leerzeile","") .print() , newMediaRecorder("1erbsenradiopfanne","audio") .log() .once() .record() .center() .print() .wait() )February 2, 2022 at 12:50 pm #7710
The code you need to write in the PHP script is reported at step 4 here: https://doc.pcibex.net/how-to-guides/recording-multimedia/#server-setup
Also, make sure you have at least one blocking upload trial before the results are sent to your server, or you’ll risk hitting “send results” before the upload completes and you won’t have lines in your results file reporting the filename(s) of the uploaded file(s)
JeremyFebruary 3, 2022 at 10:03 am #7714
thanks! I included the code now but it still gives me the same error message. Doc says in that case to check for open_basedir restrictions but there is nothing named like that on our server and, to be completely honest, I also don’t understand what that means. I tried to work around that by just giving the audios/, its subdirectory uploads/ end the saveRecordings.php within audios/ all possible permissions, so maybe I am looking in the wrong direction? I also replaced the Link in the PHP script with * to avoid spelling mistakes, but that also didn’t work.
By blocking upload trial, do you mean something like
UploadRecordings("label","block")? Also, would you recommend including an Upload trial after every recording?
JonesFebruary 3, 2022 at 11:32 am #7716
When I visit https://amor.cms.hu-berlin.de/~anamjoya/phonologie/audiorecordings/audiorecordings.php I just get a blank page, when I should at least get a
PermissionDeniedErrorerror message. Plus, when I visit https://amor.cms.hu-berlin.de/~anamjoya/phonologie/audiorecordings/ (the parent directory) the file size is 0, suggesting that the file is sill blank. Did you double-check that you indeed edited and saved the online version of your PHP file?
By blocking upload trial, do you mean something like UploadRecordings(“label”,”block”)? Also, would you recommend including an Upload trial after every recording?
By default PennController inserts a blocking upload trial before sending the results, so in the absence of any explicit
UploadRecordingsin your script you would already have a blocking upload trial. But if you want to control when that happens, yes, using
UploadRecordings("label")is the way to go (the second parameter is optional, it will default to
"block"). If you have many recordings, it would be a good idea to intersperse non-blocking upload trials over the course of your experiment too, so your participants don’t have to wait a long time for upload to complete at the end. If you just have one or two short recordings, it might not be worth it
JeremyFebruary 3, 2022 at 11:59 am #7718
sorry, I forgot to add: we switched to a different server ( https://userpage.fu-berlin.de/jonesanam/audios/saveRecordings.php ). The things I said in my last comment apply to the new server. When I try to open that link (or the parent directory), i get error messages. Does that mean our issue lies probably within the server? When trying to open the image directory ( https://userpage.fu-berlin.de/jonesanam/stimuli/ ), i also get an error message (however, displaying these in ibex works just fine).
Thank you for the explanation with the upload trials, too! 🙂
JonesFebruary 3, 2022 at 1:13 pm #7719
The server at userpage.fu-berlin.de indeed seems to impose narrower restrictions than the one at amor.cms.hu-berlin.de
It is true that https://userpage.fu-berlin.de/jonesanam/stimuli/ is not publicly accessible, but the images you upload there are publicly accessible (see, for example, https://userpage.fu-berlin.de/jonesanam/stimuli/1erbsenradiopfanne.png)
The PHP script’s address, however, returns a 500 error: https://userpage.fu-berlin.de/jonesanam/audios/saveRecordings.php. It might be that they refuse to serve PHP scripts altogether, or that something is wrong with part of the configuration somewhere. It’s really hard to tell, a 500 error is very generic. You said you made sure your PHP file is executable (you could try permission code
JeremyFebruary 9, 2022 at 3:02 pm #7731
thanks again for your answer. Correct, I double-checked all permissions on all files and directories. I also went over URL spellings etc. and the how-to page about media recording, too. In the mean time, I also talked to several IT people from my institution but sadly, this matter remains mysterious. Together we tried including a .htaccess file in audios/ (containing
php_value open_basedir "~public_html/audios/uploads", which did nothing and is now empty) and after that a .user.ini file in public_html/ (containing
PHP_INI_PERDIR PHP_INI_ALL error_log = /home/j/jonesanam/php-error.log, which also did nothing).
However, PHP configuration in general should be possible as it appears in the FAQ, which say to include a .user.ini file in public_html to configure PHP settings meanwhile only PHP_INI_PERDIR and PHP_INI_ALL classes are allowed (I am not sure what that last part means, though, I just typed the code in the file and gave it reading and executing permissions).
I’m starting to wonder if my institution’s server is somehow broken or incompatible with certain parts of IbexFarm… Is there anything else I could try? 🙁
JonesFebruary 9, 2022 at 6:44 pm #7734
I guess the first question to answer is, is there an issue with that PHP script in particular, or with executing any PHP script from your folder. You could try uploading another file called
hello_world.phpin the same folder with this content:
<!DOCTYPE html> <html> <head> <title>Hello, World! Page</title> </head> <body> <?php echo 'Hello, World!'; ?> </body> </html>
Then, if you also get a 500 error when visiting https://userpage.fu-berlin.de/jonesanam/audios/hello_world.php it means there is an issue with how PHP and PHP permissions are configured regarding your folder. Unfortunately, if that turns out to be true, and your IT cannot assist you, I’m afraid I won’t be of much help either
If you see “Hello World,” we’d have to determine where in the PHP code the problem comes from
JeremyFebruary 10, 2022 at 11:01 am #7738
thank you so much! I talked this through another time with my institution’s IT support and we noticed that certain additional permissions make the server block the PHP entirely (in case somebody else with the same problem reads this thread: no writing permissions for group and global were allowed anywhere in public_html). Now it finally works!
I noticed that recordings are named after their respective mediarecorder element and saved together in a zip archive, which is perfect. Is it possible to automatically name the zip, too? By default, it seems to be a random order of letters and numbers, which would make it hard to connect the recordings with our meta data. Ideally, we would like to automatically name each zip after the TextInput where we let our participants type in their anonymization code (but if we had a possibility to include that in the file names or have an extra file in the archive that just contains the anonymization code, that would also do). I suspect it will have something to do with modifying the UploadRecordings environment, right?
JonesFebruary 10, 2022 at 12:33 pm #7739
Glad to read that you’ve fixed the PHP issue
UploadRecordingstrials will compress in a single zip archive all the recordings made at the time the trial is executed, which haven’t been uploaded yet. If you have a single
MediaRecorderelement in each trial and you insert an
UploadRecordingstrial after each recording trial, and assuming each
UploadRecordingssuccessfully uploads its zip archive in time before the next recording has completed, then each uploaded zip file will indeed contain a single recording. However, there are plenty of situations where zip files will contain more than one recording, as you can imagine. This is why you cannot name zip files based on single elements (or even single trials) and PennController simply randomly generates a unique filename
I understand it might not make for the most straightforward data processing, but the results file lists all the filenames of the archives that were uploaded for a given submission (look for the UploadRecordings lines), so you can unzip the content of those files in a dedicated subfolder (which you can name after whatever participant-identifying string you use) and look for the recording files named after the MediaRecorder elements in those subfolders
JeremyFebruary 10, 2022 at 12:45 pm #7740
Ah – I must have overlooked the line in the results that indicates the name of the zip file. That’s definitely enough to connect the data and we should now be good to go with this experiment. Thanks a lot, once again you saved the day 😀
All the best,
JonesFebruary 10, 2022 at 12:57 pm #7741
Just remember, you need at least one blocking
SendResultsto make sure the last recordings have successfully uploaded and a line with the corresponding’s zip filename has been added to the results file before it’s too late. Normally such a blocking
UploadRecordingstrial is automatically added, but you can always add one manually too just to be extra sure
- You must be logged in to reply to this topic.