calling up the sound recorder inline
in OpenSesame
Hi everyone,
I want to call up the sound recorder in an inline script - is that possible? It seems really simple, but I can't find the answer anywhere...
The experiment is a simple random automated picture naming test & looks as below. It all works as it should in terms of displaying the stimuli; I just can't figure out how to call up the recorder in the script. I put in comments in the run phase where recording should start/stop.
I'm grateful for any advice!
Prepare phase:
from random import shuffle
global pic_list
pic_list = range(1,100)
shuffle (pic_list)
global pic_list
pic = pic_list.pop()
#prepare sampler
src=pool['ding1295ms.wav']
my_sampler = sampler(src, volume=.4)
#prepare fixdod
fixdot_canvas = canvas()
fixdot_canvas.fixdot(color='white')
#prepare cue canvas
cue_canvas=canvas()
path=exp.pool[u'cue_wym.png'] #cue tells participant what language to name the pic in
cue_canvas.image(path, scale=.1)
#prepare target canvas
target_canvas = canvas(background_color=u'thistle')
path=exp.pool[u'RANstim_%2d.png' % pic]
target_canvas.image(path, scale=.2
#prepare blank canvas
blank_canvas=canvas()
Run phase:
my_sampler.play()
fixdot_canvas.show()
clock.sleep(995)
cue_canvas.show()
clock.sleep(495)
#Recording should start here & have to define .wav format and the output file (path + pic number)
target_canvas.show()
clock.sleep.(495)
blank_canvas.show()
clock.sleep(3995)
#stop recording
Comments
...of course, I also have to add the logger as well...
I've been fiddling, but still no properly running experiment. Here are my attempts so far:
—— I coped the script from the recorder item...
... and inserted it in the run phase where I want recording to start. I also added soundrecorder.stop() at the end of the script.
This threw a syntax error, pointing to the last e in samplerate.
—— I tried to put the fixdot & cue in one script within a sequence, followed by the start_recorder, then a script for the target & blank canvas, then the stop_recoreder. There were two problems with this:
a. the recordings were split second, not the 4.5 seconds from the target display until the end of the blank canvas as I intended (I suppose this is because clock.sleep pauses the whole experiment rather than determining the canvas display times while the experiment continues (is that right?)).
b. there was only one wav file, despite the "append suffix to filename" setting.
I hope someone has a suggestion for getting this experiment in order! Thanks in advance.
Forgive my impatience @sebastiaan, do you have any ideas about this? My other experiments are working without a hitch & I really enjoy the software. I'm off to the field in a couple days and I'm stressing out that I can't get this particular one to work. It's probably something really basic – I started with Python and OpenSesame at the same time. If you have some idea about why it isn't working, I'd really appreciate it!!!
Hi Bob,
Could you upload the experiment? (And necessary files in case it depends on something)
Eduard
Gladly! But the file is too big to post here - 201mb. Can I email it to you somehow?
upload it somewhere and post the link here. Or reduce the size of it. 1-2 trials would be enough to find out what is going on, I wouldn't need all the necessary files to look at the error you get, right?
Eduard
OK, here it is.
https://we.tl/zBEKz1hT8a
It's not so much an error. In the first post above, I just couldn't figure out how to call on the sound recorder from the script. Later, I tried a workaround by breaking up the script in two parts and adding the recorder start and stop in the gui, but then only one wav is logged and it's way shorter than the stimulus display and the blank canvas (I thought maybe clock.sleep() also stops the recorder..?). In any case, my inexperience is getting the better of me - I'd appreciate any advice!!
I'm very sorry, but I have to skip this one. I just tried to install the plugins (and in particular pymedia) on my system but kept on failing. Therefore, I can't try your experiment and see what is going on. Sorry
Eduard
OK, thanks for trying!!!
Do you happen to know:
a) if there's generally a particular command to activate the sound recorder in an inline script?
and
b) if clock.sleep() pauses everything, incl. the recorder, and if so whether there's another .sleep that would not pause the recorder or a way to set the display duration in the script without sleeping the clock?
I've tried searching all this stuff in the documentation and forum, but with no luck...
b) clock.sleep() pauses the experiment, but it doesn't stop processes that were started and don't depend on Opensesame anymore, e.g. playback does not stop. therefore, I don't think that the
clock.sleep()
causes your issues. But still, you can try it out.a) Don't think so, but not sure.
Eduard
...or maybe another way to record audio without the recorder plugin? Some of the older threads discuss something like this, but I think with previous releases of the program.
Hi BaaBob,
(A quick reply without having fully read this discussion.) The
sound_recorded
plugin, which was created by @Daniel, is not as far as I know intended to be used from a script. However, if you search this forum for terms such as 'pyaudio record', you will find a few alternative approaches. For example in this discussion:Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks, @sebastiaan !!
I have seen some of those threads about pyaudio; as a sort of noob, it all seemed way more complicated than I needed. I'll give it a go now. Just a quick follow up question, re the script in that link that you posted, do you recommend putting parts of it in the prepare phase? Or should it all go under run? I will fiddle around with it, but I am checking reaction time, so I should be as optimal as possible.
It does seem like the sound_recorder isn't compatible with scripts. I got my it to sort-of work, by inserting it between two scripts in the sequence, but each trial would overwrite the file from the last one...so I'd end up with a single file all the time. I also tagged @Daniel in another old thread related to this issue, where someone else complained about getting a just a single file.
I'll post the code if I can get the experiment to run. nog bedankt!
So, gentlemen, the sound_recorder is out. Thanks once again for the suggestions! I now have something that's at least functional, but still not quite right. Taking the code from the first attempt I made & @sebastiaan 's suggestion to look at PyAudio, I have come up with the following:
preliminary script randomized the stimuli
then the prep phase of a script within the trial sequence
...and the run phase
This reliably records individual trials within the sequence. However, the timing is off. It seems like the record duration gets tacked on to the cue_canvas (so it displays for ca 2.5secods) and records during the cue_canvas display instead of the target_ and blank_ canvas as it should. The recording should start at the precise moment of target_canvas.show() and continue through the end of blank_canvas.show(). Any ideas what I'm doing wrong?
Hi Again. my experiment is now working as it should. Basically I had some things out of order. I'm pretty new with python and I didn't really understand what all the bits did at first (still, even, but it works ). Here is the code that works as it should. I added "import time" to the prep phase to check the timing. The run phase is as follows (commented out the time checking and stuff that was in the wrong place from my post yesterday):
Thanks @sebastiaan & @eduard for your suggestions!!!