Howdy, Stranger!

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

Supported by

Bad audio quality

Hi,
I'm back with yet another question. ;-)
In my experiment the quality of the audio stimuli is really decisive. But the sound quality of my sampler items (voice recordings) is much worse when played in OpenSesame than when I open the same files in any other audio device on the system. They sound somewhat tinny with some noise added.
I run OpenSesame under Mac OS X and use the legacy backend, but expyriment gave the same results (while psycho always crashed before I even got to the stimulus generation). I played around with the sampler settings for legacy, but nothing changed. As it is the default, I think PyGame is used for the sampler although I don't know where it is specified. Is there any chance that audio quality improves under PyAudio? Or anything else I can do about it?
Best,
Sophia

Comments

  • Hi Sophia,

    You're probably hearing a kind of crackling noise, right? That happens when the buffer is too small. If you increase the sound buffer size (under back-end settings), the problem should go away.

    As it is the default, I think PyGame is used for the sampler although I don't know where it is specified. Is there any chance that audio quality improves under PyAudio? Or anything else I can do about it?

    Yes, PyGaze is used by the sampler. PyAudio should be fine as well, but I don't think it's necessary: I would first check if increasing the buffer size resolves the issue.

    Cheers,
    Sebastiaan

  • Hi Sebastiaan,

    Thank you very much for your answer!
    Yeah, I think you could describe it as a crackling noise. It sounds like a kind of vibration at the end of almost every sound file/word. I already tried increasing the buffer size, but it didn't help. Just to test it I now set the buffer at 20000. Still nothing changed. (The values for sampling frequency etc. correspond to the audio files.)

  • The problem got even worse now: About 3/4 through the experiment, the audio quality started to deteriorate progressively until in the end it wasn't even perceivable anymore that my audio stimuli were human speech. They sounded like really bad radio crackling and were shorter in duration than the original audio files.

    I use a MacBook Pro (from 2015 with Mac OS 10.11.6) and connect a condenser-microphone-headset via iTrack Solo (an audio interface with USB connection). The problem only occurred when I ran OpenSesame with this specific hardware, i.e. everything is fine when
    1) running OpenSesame, using the Mac's internal loudspeakers (beside the less-than-optimal sound quality described in the original post)
    2) playing the exact same audio files (for hours) over the headset and iTrack Solo without OpenSesame.

    Disconnecting the USB device when sound quality started to get ugly and then reconneting it again right after also helped. But that's not something I would want to do during the actual experiment...

    So is there anything I can do about it?
    I was considering again to try PyAudio. I installed it but I don't know where in the code to specify that it should be used in this experiment.
    Also, how and where in the script can I tell OpenSesame to use another audio player?

    Any advice is greatly appreciated! I really hope that I can test the first subjects the next two days...

  • That sounds like one of these device-specific problems. Annoying, and difficult to pin down and solve.

    I was considering again to try PyAudio. I installed it but I don't know where in the code to specify that it should be used in this experiment. Also, how and where in the script can I tell OpenSesame to use another audio player?

    The sampler cannot use PyAudio. You have to write a script to do so. But that's not very difficult, and you can almost copy-paste the examples from the PyAudio docs.

    Below you see how to play back a wave file. The script assumes that the wave file is in the file pool, and that its name is specified by the variable my_sound.

    Let's see whether this resolves the distorted sound—difficult to predict.

    """PyAudio Example: Play a WAVE file."""
    
    import pyaudio
    import wave
    import sys
    
    CHUNK = 1024
    # We assume that the sound file is specified by the variable my_sound
    path = pool[var.my_sound]
    
    wf = wave.open(path, 'rb')
    
    p = pyaudio.PyAudio()
    
    stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                    channels=wf.getnchannels(),
                    rate=wf.getframerate(),
                    output=True)
    
    data = wf.readframes(CHUNK)
    
    while data != '':
        stream.write(data)
        data = wf.readframes(CHUNK)
    
    stream.stop_stream()
    stream.close()
    
    p.terminate()
    
  • Hi Sebastiaan,
    First of all, thank you very much for your really quick answer! That's very kind of you!
    I've been trying to execute the piece of code you gave me (just this piece, not integrated in my experiment) for many hours now but cannot get it running.

    Where and how do I specify the variable that [var.my_sound] refers to?

  • And one more question:
    Where would I integrate the script into my experiment? Can I just exchange the sampler item for the inline script (and change the item in the experiment sequence)?

    Here are the parts of the experiment that I guess are most important:

    define sequence experiment
        set flush_keyboard no
        set description "Runs a number of items in sequence"
        run welcome always
        run digit_recall_loop always
        run instructions1 always
        run instructions2 always
        run practice_loop always
        run end_of_practice always
        run block1 always
        run end_of_block1 always
        run block2 always
        run goodbye always
    
    define sequence trial_sequence
        set flush_keyboard yes
        set description "Runs a number of items in sequence"
        run blank_screen always
        run audio_stimulus_loop always
        run fixation_dot always
        run blank_screen always
        run clicks_slow always
        run fixation_dot always
        run blank_screen always
        run clicks144 always
        run mouse_response always
        run logger always
    
    define loop audio_stimulus_loop
        set source_file ""
        set source table
        set repeat 2
        set order sequential
        set description "Repeatedly runs another item"
        set cycles 1
        set continuous no
        set break_if_on_first yes
        set break_if never
        setcycle 0 empty_column ""
        run audio_stimulus
    
  • I've been trying to execute the piece of code you gave me (just this piece, not integrated in my experiment) for many hours now but cannot get it running.

    The code refers to the OpenSesame variable store (var), so it will never work as a standalone script. The examples on the PyAudio site are standalone.

    Where and how do I specify the variable that [var.my_sound] refers to?

    You presumably specified the name of the sound file in a loop, right? This script simply assumes that you used the variable name my_sound. var.my_sound is the Python way of referring to this variable, just as [my_sound] is the OpenSesame way. So var. is not part of the variable name. See also:

    Where would I integrate the script into my experiment? Can I just exchange the sampler item for the inline script (and change the item in the experiment sequence)?

    Exactly. You would replace the sampler by an inline_script with this code in the run phase.

  • Hi Sebastiaan,

    Thank you very much for your helpful explanations! Sorry for asking all these basic questions; I'm totally new to scripting and the mixture of OpenSesame script and Python script can be quite confusing for beginners.

    You presumably specified the name of the sound file in a loop, right?

    Yes, I did. I now integrated the script into my experiment and the variable was interpreted correctly. The experiment still crashed because the first sound file wasn't found in the file pool but at least its name was correct in the error message. (So that's a point I can continue working from.)

    The exception message was 
    exception message: [Errno 2] No such file or directory: u'be_go'
    'be_go' is the name of the first audio file to be played. Do you know what the letter u means?

  • 'be_go' is the name of the first audio file to be played.

    It's probably not though—I imagine there's an extension that indicates the file format. And this extension is part of the name. So it would be be_go.wav. (This snippet assumes that it's a wave file.) So you can either add extensions to the names in your loop table, or append it in the script like so:

    path = pool[var.my_sound + u'.wav']
    

    Do you know what the letter u means?

    It's a technicality: The u prefix means it's a unicode string, which is a special string type that is good for working with non-ascii characters.

  • edited December 2016

    Thank you so much!!! It works now and my first impression is that the audio quality is better than in the sampler. A longer test will show if the problem of the gradual deterioration of the sound quality is also solved.

    It's probably not though—I imagine there's an extension that indicates the file format. And this extension is part of the name.

    Ah, ok, I see the error in my reasoning here. I assumed that the file extension was taken for granted because it was specified in the code that the file to be opened is a wave file: wf = wave.open(path, 'rb')

    And thanks for your blog and manual links! I had searched the web for information on variables in python but forgotten the most obvious source...

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