Hi everyone,
It seems like I am having the similar problem as others when I tried to record an audio response via builder. The first error code is that: portaudio error in Pa_Initialize: Internal PortAudio error. And this seems to be the problem between the computer config and the Pyo config. I found that they have different sampling rates, but I can’t change it…
In addition to that, I have another error as:
"portaudio error in Pa_Initialize: Internal PortAudio error
Traceback (most recent call last):
File “C:\Users\RA\Desktop\HungShao QP1\test2_lastrun.py”, line 142, in
sound_file = sound.Sound(‘A’, secs=-1)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\sound\backend_pyo.py”, line 289, in init
self.sampleRate = pyoSndServer.getSamplingRate()
AttributeError: ‘NoneType’ object has no attribute ‘getSamplingRate’
"
I have tried to specify the sampling rate to 48000 in the coder view but still received the same error.
I was wondering if anyone could point a direction for me to solve this problem. And is there a stable way to record an audio in Psychopy? This would save a lot of for the data analysis if Psychopy can save each audio response for me.
Thank you so much and apologize for such a long post.
Pyo uses WASAPI as its default audio host on windows. If you can’t change neither the system’s sampling rate or psychopy’s one, you should try setting the Server’s host to “directout”, it will gently do sampling rate conversion in background and will not complain about sampling rate mismatch. You need to set the “winhost” attribute of pyo.Server to “directout”.
Olivier
Hi @belangeo,
Thank you so much! I figured a way to change the sampling rate of the microphone so that the sampling rate matches the one in Pyo. However, I still received an error, though a somewhat different one:
Traceback (most recent call last):
File “C:\Users\RA\Desktop\HungShao QP1\test2_lastrun.py”, line 642, in
mic_1 = microphone.AdvAudioCapture(name=‘mic_1’, saveDir=wavDirName, stereo=False)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\microphone.py”, line 357, in init
self.setMarker()
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\microphone.py”, line 402, in setMarker
sampleRate = sound.pyoSndServer.getSamplingRate()
AttributeError: ‘NoneType’ object has no attribute ‘getSamplingRate’
I specified the sampling rate in this line:
psychopy.microphone.switchOn(sampleRate=44100, outputDevice=None, bufferSize=None)
But I still got the error.
Do you know what the problems might be?
Thank you!
The sampling rate you specify in this line,
psychopy.microphone.switchOn(sampleRate=44100, outputDevice=None, bufferSize=None)
is pyo’s sampling rate, for both input and output.
Now my guess is that the system uses a different sampling rate (this is the mismatch), either for recording or for playback (you need to check both in the Sound panel). Make sure that your system also have at least 2 ins / 2 outs available
What would be nice is to ask psychopy’s devs to add the ability to change the “winhost” attribute of the pyo.Server at initialization!
Hi Olivier @belangeo,
Thank you again! I am able to change the sampling rate to 44100 for both of my input and output device (input: M-Audio Mobile Pre USB, outpust: Microsoft’s speakers/headphones). And I have used your script to test the audio configuration, everything seems to be working fine. However, I still have the same error code as before:
File “C:\Users\RA\Desktop\HungShao QP1\test2_lastrun.py”, line 642, in
mic_1 = microphone.AdvAudioCapture(name=‘mic_1’, saveDir=wavDirName, stereo=False)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\microphone.py”, line 357, in init
self.setMarker()
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\microphone.py”, line 402, in setMarker
sampleRate = sound.pyoSndServer.getSamplingRate()
AttributeError: ‘NoneType’ object has no attribute ‘getSamplingRate’
I noticed that both of the devices are 2-channels, would this be the problem?
When I tried to change the winhost to ‘directout’ and to specify the duplex mode, it gives an an error code saying, “invalid syntax”. I tried to change it in the backend_pyo.py file, as attached. Is this the wrong file to change?
Would this be the problem of my microphone interface overall? This interface is an old one which no longer supports my macbook anymore. Would you recommend me to buy a new interface and try again?
Thank you so much for your helps. I really appreciate it.
If you can run this script without problem from the Command Prompt, then there is no problem with your interface:
from pyo import *
s = Server(winhost="directsound").boot()
a = Input([0,1]).out() # Use headphones to avoid feedback!
s.gui(locals()) # Press the Start button...
I just checked my previous answer and I realized that I told you to use “directout” as the winhost argument, I wanted to write “directsound”… Sorry.
I don’t use psychopy myself but reading the backend_pyo.py file, it seems that you can set the audio host in the preferences. I think it’s the way to go.
Hi @belangeo,
Thank you! I have changed it to “directsound” and the interface was tested fine by your code given above. I still have the same error in PsychoPy. I have no idea what’s going on here now…