Howdy, Stranger!

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

Supported by

[solved] "audio switching" with OpenSesame

edited September 2015 in OpenSesame

Dear fellow Coders,

I'm new to OpenSesame and have a question for the more experienced coders. To provide a little background: We employ auditory localization tasks in our experiments. Typically, two (different) sounds are simultaneously presented from two (out of x) speakers. The specific speakers are defined on a trial-by-trial basis. Therefore, I'm looking for a program that can "send" the sound signal to different speakers.

We previously had a hardware solution for the issue: Specific speakers were defined in another software (LiveCode) and transmitted to a (custom made) audio switch device via the COM-port. The audio switch device then send the left/right channel of a stereo file to the specified speakers. I wonder if it is possible to circumvent the audio switch device (which is no longer available) and directly specify sound channels (e.g. via a sound card or an audio interface) with OpenSesame.

Any ideas? Thanks in advance for any suggestions. I'm mainly interested if OpenSesame is capable of such an operation.

Cheers,
Malte

Edit: The feature we are (desperately) looking for is similar to the "Sound Mixer" implemented e.g. in the Presentation environment.

Comments

  • edited 11:54AM

    Hi Malte,

    If there is a Python package somewhere out there that can do this operation it will most likely also work from within OpenSesame. Unfortunately, I have no clue whether it exists, or anything specific about how to tackle the problem.

    Sorry,

    Eduard

    Buy Me A Coffee

  • edited 11:54AM

    Hi Eduard,

    it's a good thing to hear that it is (generally) possible. I came across a rather convenient solution for the "present from multiple speakers"-part of the problem: Following this post, it can be easily done for mono/stereo files by adding more entries to the channel_map in PyAudio. The (slightly modified) code looks like this:

    import pyaudio
    import wave
    import sys
    
    chunk = 4096
    
    PyAudio = pyaudio.PyAudio
    
    if len(sys.argv) < 2:
    print("Plays a wave file.\n\nUsage: %s filename.wav" % sys.argv[0])
    sys.exit(-1)
    
    wf = wave.open(sys.argv[1], 'rb')
    
    p = PyAudio()
    
    channel_map = (0, 1, -1, -1, -1, -1, -1, -1)
    
    try:
    stream_info = pyaudio.PaMacCoreStreamInfo(
    flags=pyaudio.PaMacCoreStreamInfo.paMacCorePlayNice, # default
    channel_map=channel_map)
    except AttributeError:
    print("Sorry, couldn't find PaMacCoreStreamInfo. Make sure that "
    "you're running on Mac OS X.")
    sys.exit(-1)
    
    print("Stream Info Flags:", stream_info.get_flags())
    print("Stream Info Channel Map:", stream_info.get_channel_map())
    print("channels",wf.getnchannels())
    
    print('sample width',wf.getsampwidth())
    
    stream = p.open(
    format=p.get_format_from_width(wf.getsampwidth()),
    channels=wf.getnchannels(),
    rate=wf.getframerate(),
    output=True,
    output_host_api_specific_stream_info=stream_info)
    
    data = wf.readframes(chunk)
    
    while data != '':
    stream.write(data)
    data = wf.readframes(chunk)
    
    stream.stop_stream()
    stream.close()
    
    p.terminate()
    

    Is it possible to implement PyAudio in OpenSesame by manually editing the code of e.g., a sampler item? Or would that conflict with the ways sounds are played by OpenSesame?

    If it is possible, can someone provide an example of how it can be done? I don't mind digging some more into libraries/modules but providing an example for the code in question would help me (as a novice) a lot.

    Thanks again!

    Malte

  • edited 11:54AM

    Is it possible to implement PyAudio in OpenSesame by manually editing the code of e.g., a sampler item? Or would that conflict with the ways sounds are played by OpenSesame?

    Sure, you can add arbitrary Python code using the inline_script item. If you search this forum for 'pyaudio', you'll find various examples of people using pyaudio this way.

    Cheers!
    Sebastiaan

  • edited 11:54AM

    Hi Sebastiaan,

    thanks for the quick reply! I will try to make the modified code from PyAudio work in OpenSesame. I will share any but (hopefully positive) outcome of it in the forum.

    Thanks again!

    Malte

  • edited December 2015

    Hello OpenSesameTeam,

    I m trying to implement an inline script (separate item) to play a wav file using the script that I found here http://people.csail.mit.edu/hubert/pyaudio/.
    I get an IO error in the following line:

    wf = wave.open('drip.wav', 'rb')

    (The drip.wav file is located on the same folder as my script.)

    My o/p:

    Error while executing inline script

    phase: run
    item: inline_script
    line: 159
    exception message:
    exception type: IOError

    Traceback:
    File "/Applications/OpenSesame.app/Contents/Resources/lib/python2.7/libopensesame/inline_script.py", line 173, in run
    File "/Applications/OpenSesame.app/Contents/Resources/lib/python2.7/libopensesame/python_workspace.py", line 111, in _exec
    Inline_script, line 20, in
    File "wave.pyc", line 509, in open
    File "wave.pyc", line 160, in init
    IOError: [Errno 2] No such file or directory: 'drip.wav'

    Any ideas how to resolve this issue of IOError?
    Thank you very much,
    V

  • edited 11:54AM

    Hi V,

    it would be help if you could provide the complete inline script that causes the error. At first glance, it seems that the file could not be retrieved. You might try to specify a path to "drip.wav".

    Cheers,

    Malte

  • edited 11:54AM

    Dear Malte,
    thank you very much for your response, I resolved the issue. It is necessary to specify the absolute path of the file.
    Take care!

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