[open] Replacement function for numpy.opentxt in Droid backend/Android environment?
Hello!
I'm a coding novice and trying to import an experiment I programmed in a different proprietary runtime over to OpenSesame, as I'm interested in a portable, tablet version of my experiment. I've worked and worked on it, and got it to work just fine on my computer - but it won't work on my tablet.
I should have looked closer at the API for the Droid backend, but I've been hobbling together my code based on some of the discussions here in the forum. Namely, I have multiple lines of text I want to present in order to the participants in each sequence - my experiment is intended to be used with children as well as adults, and stories and varied pictures are required to keep my participants' interest.
Rather than creating the lists of pictures, text lines, and sounds inside OpenSesame, I was using the method found here ( http://www.cogsci.nl/forum/index.php?p=/discussion/502/solved-reading-in-stimuli-list/p1 ) and here ( http://forum.cogsci.nl/index.php?p=/discussion/469/solved-selective-sampling-with-a-ratio-help-please ) and using text files read in through the NumPy modules. My code at the beginning of the experiment looks like this:
path_instructionslist = exp.get_file("bmsaa_kids_instructions.txt")
path_instructionspicslist = exp.get_file("bmsaa_kids_instructions_pics.txt")
...
global instructionslist, instructionspicslist
...
import numpy as np
instructionslist = np.loadtxt(path_instructionslist, dtype = str, delimiter = ";")
instructionspicslist = np.loadtxt(path_instructionspicslist, dtype = str, delimiter = ";")
and then later, before the relevant blocks, an inline script:
instructionslist = list(instructionslist)
instructionspicslist = list(instructionspicslist)
instructions_text = instructionslist.pop(0)
instructions_pic = instructionspicslist.pop(0)
exp.set("instructions_text", instructions_text)
exp.set("instructions_pic", instructions_pic)
It works beautifully on my windows desktop when I'm testing it (as NumPy is in included in the Windows environment), but when I attempt to run it on my Samsung tablet, it crashes out (well, exits gracefully without a word), and my traceback is that NumPy doesn't exist to be called in the Android environment. Whoops!
I've been desperately looking through the Python 2.7 documentation, but can't figure out what built-in Python function I can call to mimic the functionality of NumPy's loadtxt. I've tried the basic 'open()' -
instructionslist = open(path_instructionslist)
instructionspicslist = open(path_instructionspicslist)
in place of the 'np.opentxt(path_instructionslist)' in my first example, but then I get an error/traceback that the soundfile I want to call first doesn't exist, as it's added an extra bit of whitespace to my variable name. E.g. instead of 'silence' I get 'silence ' - so while 'silence.wav' exists, 'silence .wav' does not, hence the traceback.
What should I add to my code/what function can I call to get my program to work again? I'll keep poring over the documentation, but any and all help would be appreciated. Thank you!
Comments
Okay - I've done a little googling and checked around, and this is what I came up with - problem is, while it should work (as far as I can tell), it still doesn't. The first bit is still the same; I've changed after I globally define my variables to read as thus:
and so on and so forth. I've checked my code in PyCharm; when I run
I get what I'm expecting; my output looks like this:
So far so good - no extra whitespace at the end, the variable type IS list, and it seems to be doing what I ask - those are the values in the text file.
The inline_script at the beginning of the first instructions loop/sequence is such:
I can probably take out the first three lines, as they're redundant by this point, right? That's not the main question though.
The text and pictures on the canvas item in the sequence are dictated by [instructions_pic] and [instructions_text], and the sound in the sampler is dictated by [instructions_sound].
Relevant sampler script:
Now when I attempt to quick-run my experiment, though, I get the following traceback:
I cannot figure out for the life of me where it's getting "D" as the value of instructions_sound. Adding a line to PyCharm asking it to return the first item in the instructionssoundslist list gives me 'silence' (what I'd expect), but that's apparently NOT what OpenSesame is returning. I'm at my wits' end right now - according to PyCharm, my code SHOULD work. According to OpenSesame, it doesn't. Any ideas on what to tweak would be greatly appreciated!
Hey,
This sounds odd. Have you tried to use your other two variables (text and image) in a similar way, i.e. in a
sketchpad
? If it works for them, it could be a problem of thesampler
item. I couldn't try it myself, because I don't have thewav
-files, but displaying the words in that way seems to work. If you could share your audio files, I can try it again and see whether I can reproduce this error.Yes, I think so.
Thanks,
Eduard
I didn't fully read this discussion (so this is a bit of a hunch), but this comment struck me, and I think something like the following is going on.
D:/HDD Documents/2014-2015/BMSAA
D
.pop()
the first character (i.e.D
) from this list, and set that as the variableinstructions_sound
.Could it be something like this?
Check out SigmundAI.eu for our OpenSesame AI assistant!