Howdy, Stranger!

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

Supported by

[solved] Recording speech response

edited May 2012 in OpenSesame


First off, thanks for all the efforts you're putting into this package. It looks and works amazing.

I want to do a sort of picture naming experiment; a picture appears on the screen and the participant has to describe it. In my case, recording for abour five seconds during the presentation of the picture would be ideal. I tried to build on the code of the voicekey trigger example, but I get stuck at the point where I need to write the data to a wave file. The only way I've seen this done is by using the wave library (import wave), but OpenSesame complains when I put that in the code..

Any help appreciated.



  • edited January 2014

    Hi Martijn,

    First off, thanks for all the efforts you're putting into this package. It looks and works amazing.


    As luck would have it, the PyAudio documentation has an example that does exactly what you want to do, and it simply works (for me) if you paste it into an OpenSesame inline_script.

    I changed it a tiny bit to use the subject_nr and count_inline_script to determine the output file name, but aside from that the example comes straight from:

    """ Record a few seconds of audio and save to a WAVE file. """
    import pyaudio
    import wave
    import sys
    chunk = 1024
    FORMAT = pyaudio.paInt16
    CHANNELS = 1
    RATE = 44100
    WAVE_OUTPUT_FILENAME = "%d_%d.wav" % (self.get('subject_nr'), self.get('count_inline_script'))
    p = pyaudio.PyAudio()
    stream = = FORMAT,
                    channels = CHANNELS,
                    rate = RATE,
                    input = True,
                    frames_per_buffer = chunk)
    print "* recording"
    all = []
    for i in range(0, RATE / chunk * RECORD_SECONDS):
        data =
    print "* done recording"
    # write data to WAVE file
    data = ''.join(all)
    wf =, 'wb')

    Good luck!


  • edited 3:02PM

    Hi Sebastiaan,

    Thanks for the reply, I tried your script (and my own script that looks very much the same), but Opensesame complains it cannot find pyaudio (on my mac) and on windows it can't find the wave module:

    Traceback (most recent call last):
    File "libopensesame/inline_script.pyc", line 112, in run
    File "", line 3, in
    ImportError: No module named pyaudio

    Traceback (most recent call last):
    File "libopensesame/inline_script.pyc", line 112, in run
    File "", line 3, in
    ImportError: No module named wave

    Do I need to install something separately?

    Thanks again,

  • edited 3:02PM

    Ah right, of course, the 'wave' module isn't included! You cannot really install additional packages when using the binary distribution, but you can when using the Python portable package. I haven't done this myself, but Edwin will probably be able to help you, if you ask him on the forum:

    Alternatively: I'll also include the module in the next pre-release of OpenSesame, so you could wait until 0.26-pre7 (or later) appears and you could use that.

  • edited 3:02PM

    Thanks, I'll look into the portable package. Is the pyaudio package also not included in the mac version, because that is the point where OpenSesame stops on my mac.

  • edited 3:02PM

    Indeed, PyAudio is not included in the Mac OS package. I'll make a note of it, because I think it should be included by default.

  • edited 3:02PM

    That would be great, being able to record (chunks of) speech would, especially in combination with voicekey measurements, be very welcome to a lot of people in psycholinguistics and experimental linguistics.

  • edited 3:02PM

    Just to let you know; I tried this with 0.26 pre and it works in Ubuntu, but not in windows yet (probably because the wave module hasn't been included there yet). I haven't tested it on the mac yet.

  • edited March 2012

    You rang?

    PyAudio is a single Python-file, right? Simply add it to this directory *\opensesameportable-0.25-1-win32\PortablePython_1.1_py2.6.1\App\Lib\site-packages of the portable 0.25 version (downloadable here: ) and you should be ready to experiment! Same goes for the 0.26 (pre6) portable version, since I haven't included PyAudio in that one as well.

    Please do let me know if it works, I do not have PortAudio installed, so I can't check.


  • edited 3:02PM

    Hi Edwin,

    Sorry for the late reply. Work got in the way. That is a great suggestion and I will try it as soon as I get the change. On the other hand, I understand that the next version of Opensesame will support pyaudio and wave, so the problem might soon be solved by default. Nevertheless it is good to know that it is fairly easy to plugin additional python modules in portable Opensesame.

    Thanks again for your reply, and I'll keep you posted,


  • edited 3:02PM

    Hi All,

    It's me again. I just tested speech recoding with EE. Works like a charm!


  • edited June 2012

    Dear Sebastiaan, (and Edwin and goodbeem)
    I have been playing around with OpenSesame for a while now: not a coding-savvy experimenter, I enjoy it immensely. Lovely job, thank you so much!

    I am putting together a phonetics study and want to record the sentences read from dialogues of four lines. However, the utterances will vary in length, and so the recording should run until 'keypress', at which point the next line would be played back:

    sketchpad [dialogue], duration:keypress   # text shows throughout. (related question below)
    sampler: sound file:[dialogue]1.wav, duration:keypress # play recorded line 1
    record+store: response[dialogue]1__[subject_nr].wav #  record for me until subject presses key!
    sampler: sound file:[dialogue]2.wav, ... #...
    record+store response[dialogue]2__[subject_nr].wav #

    so, how would I include this keypress feature here?

    regarding the multi-line display, I posted a question in the (inactive) "text which appears" thread.

    Thanks again for the efforts with this great tool.

  • edited January 2014

    Hi Christerwi,

    You can change the stop criterion to anything you like. Above it was a fixed duration, but the code below shows how you can stop recording after a key has been pressed. This script is just a snippet that you need to combine with the recording part of the full script posted above.

    For more information on keyboard functions, see also

    print "* record until keypress"
    from openexp.keyboard import keyboard
    # Short timeout so get_key() doesn't block
    my_keyboard = keyboard(exp, timeout=2)
    all = []
    while my_keyboard.get_key()[0] == None: # Loop until a key has been pressed
        data = # Record data
        all.append(data) # Add the data to a buffer (a list of chunks)
    print "* done recording"

    Good luck!


  • edited 3:02PM

    Hi everyone, I tried to follow the instructions here using a Mac OS installation and encountered some problems, detailed in this thread:

    The relevant part is copied here:

    "I installed PyAudio using the mpkg script provided on the PyAudio site, and then I went through the process again and did the manual installation with PortAudio. Either way I do it, I get the same error: "ImportError: No module named pyaudio".

    I have gone through the process of copying the pyaudio installation to the directories listed in the prefs under Plug-In folders, a few of which had to be created because the installation doesn't seem to generate them, and even after a restart, cannot find the installation of pyaudio."

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 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