Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Replacement function for numpy.opentxt in Droid backend/Android environment?

edited June 2015 in OpenSesame

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

  • edited June 2015

    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:

    instructionslist = [line.rstrip('\n') for line in path_instructionslist]
    instructionspicslist = [line.rstrip('\n') for line in path_instructionspicslist]
    

    and so on and so forth. I've checked my code in PyCharm; when I run

    path_instructionssoundslist = open('bmsaa_kids_instructions_sounds.txt', 'r')
    instructionssoundslist = [line.rstrip('\n') for line in path_instructionssoundslist]
    print type(instructionssoundslist)
    print instructionssoundslist
    for line in instructionssoundslist:
        print line
    

    I get what I'm expecting; my output looks like this:

    <type 'list'>
    ['silence', 'silence', 'silence', 'silence', 'silence', 'silence', 'silence', 'silence', 'silence', 'music_alone', 'silence', 'click_alone', 'practice_synchronous01', 'silence', 'silence', 'silence', 'silence', 'silence', 'silence', 'silence', 'silence']
    silence
    silence
    silence
    silence
    silence
    silence
    silence
    silence
    silence
    music_alone
    silence
    click_alone
    practice_synchronous01
    silence
    silence
    silence
    silence
    silence
    silence
    silence
    silence
    

    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:

    instructionslist = list(instructionslist)
    instructionspicslist = list(instructionspicslist)
    instructionssoundslist = list(instructionssoundslist)
    
    instructions_text = instructionslist.pop(0)
    instructions_pic = instructionspicslist.pop(0)
    instructions_sound = instructionssoundslist.pop(0)
    
    exp.set("instructions_text", instructions_text)
    exp.set("instructions_pic", instructions_pic)
    exp.set("instructions_sound", instructions_sound)
    

    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:

    set sample "[instructions_sound].wav"
    

    Now when I attempt to quick-run my experiment, though, I get the following traceback:

    >>> 
    Starting experiment as ExperimentProcess-33
    openexp.sampler._legacy.init_sound(): sampling freq = 44100, buffer size = 1024
    openexp.sampler._legacy.init_sound(): mixer already initialized, closing
    experiment.init_log(): using 'D:/HDD Documents/2014-2015/BMSAA\quickrun.csv' as logfile (utf-8)
    experiment.run(): experiment started at Fri Jun 19 19:40:04 2015
    
    Failed to load sample in sampler "instructionssounds": 
    openexp._sampler.legacy.__init__() the file 'D.wav' does not exist
    
    
    >>> 
    

    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!

  • edited 1:40AM

    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 the sampleritem. I couldn't try it myself, because I don't have the wav-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.

    I can probably take out the first three lines, as they're redundant by this point, right?

    Yes, I think so.

    Thanks,

    Eduard

    Buy Me A Coffee

  • edited 1:40AM

    I cannot figure out for the life of me where it's getting "D" as the value of instructions_sound.

    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.

    • You have a path, for example: D:/HDD Documents/2014-2015/BMSAA
    • You cast this to a list, so you get a list of separate characters, the first of which is D.
    • You pop() the first character (i.e. D) from this list, and set that as the variable instructions_sound.

    Could it be something like this?

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games