[open] Audio recording with loop
In my experiment, participants have to give descriptions of pictures, and I want OpenSesame to make an audio recording of every description. Each picture is visible for 5000 ms, and at the onset of each picture, OpenSesame starts to record the description of the picture for 5 seconds. So far so good, but since I have about 20 pictures, I had to include a loop + sequence, and this where things go wrong. After making the recording, OpenSesame doesn't automatically move on to the next picture in the loop. Instead, I have to press a key in order to go to the next picture and sound recording.
This is the Python code I used:
""" Record a few seconds of audio and save to a WAVE file. """ import pyaudio import wave import sys from openexp.keyboard import keyboard chunk = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 RECORD_SECONDS = 5 OUTPUT_FOLDER = "C:\Program Files\OpenSesame" #WAVE_OUTPUT_FILENAME = "ppn_%d_%d_%s.wav" % (self.get('subject_nr'), self.get('count_inline_script'), self.get('plaatje')) OUTPUT_FILE = "ppn_%d_%s.wav" % (self.get('subject_nr'), self.get('pict')) FINAL_FILENAME = OUTPUT_FOLDER + OUTPUT_FILE p = pyaudio.PyAudio() stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, frames_per_buffer = chunk) print "* recording" # Short timeout so get_key() doesn't block my_keyboard = keyboard(exp, timeout=2) all =  while my_keyboard.get_key() == None: # Loop until a key has been pressed #all =  #for i in range(0, RATE / chunk * RECORD_SECONDS): data = stream.read(chunk) all.append(data) print "* done recording" stream.close() p.terminate() # write data to WAVE file data = ''.join(all) wf = wave.open(FINAL_FILENAME, 'wb') wf.setnchannels(CHANNELS) wf.setsampwidth(p.get_sample_size(FORMAT)) wf.setframerate(RATE) wf.writeframes(data) wf.close()
How can I get OpenSesame to move on to the next picture after the audio recording? Any help would be appreciated.