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.
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
Check out SigmundAI.eu for our OpenSesame AI assistant!
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.
The
samplercannot 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.
Check out SigmundAI.eu for our OpenSesame AI assistant!
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:
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.You presumably specified the name of the sound file in a
loop, right? This script simply assumes that you used the variable namemy_sound.var.my_soundis the Python way of referring to this variable, just as[my_sound]is the OpenSesame way. Sovar.is not part of the variable name. See also:Exactly. You would replace the
samplerby aninline_scriptwith this code in the run phase.Check out SigmundAI.eu for our OpenSesame AI assistant!
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.
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?
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 yourlooptable, or append it in the script like so:It's a technicality: The
uprefix means it's a unicode string, which is a special string type that is good for working with non-ascii characters.Check out SigmundAI.eu for our OpenSesame AI assistant!
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.
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...