# Massive delay using Python interface

**URL:** <https://forums.steinberg.net/t/massive-delay-using-python-interface/201826>\
**Category:** ASIO\
**Created:** [November 16, 2018, 9:30am UTC](https://forums.steinberg.net/t/massive-delay-using-python-interface/201826 "2018-11-16T09:30:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stfnrpplngr](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@stfnrpplngr](https://forums.steinberg.net/u/stfnrpplngr)\
**Post date:** [November 16, 2018, 9:30am UTC](https://forums.steinberg.net/t/massive-delay-using-python-interface/201826/1 "2018-11-16T09:30:03Z")

</div>

We want to present acoustic stimuli using the Steinberg UR22mkII. An interface in Python, we rely on the sounddevice module ([GitHub - spatialaudio/python-sounddevice: Play and Record Sound with Python](https://github.com/spatialaudio/python-sounddevice)). Unfortunately, so far, we did not manage to present our sounds in WASAPI exclusive mode. We are facing a massive delay. A detailed description of the problem is posted on Github:

> <https://github.com/psychopy/psychopy/issues/2065>
>
> I have already posted in the psychopy forum: \[Massive Sound lag using PsychoPy\](…https://discourse.psychopy.org/t/massive-sound-lag-using-psychopy-windows-wasapi-for-external-sound-card/5530). I am stuck. Trying to activate exclusive mode as described in the \[documentation of sounddevice\](https://python-sounddevice.readthedocs.io/en/0.3.12/api.html#sounddevice.WasapiSettings) results in \`PaErrorCode -9996\`.
> 
> \`\`\`
> Traceback (most recent call last):
> File "D:\\Experimente\\task1.py", line 85, in \<module\>
> sound\_1 = sound.Sound('A', secs=-1, stereo=True)
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\psychopy\\sound\\backend\_sounddevice.py", line 296, in \_\_init\_\_
> hamming=self.hamming)
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\psychopy\\sound\\backend\_sounddevice.py", line 343, in setSound
> blockSize=self.blockSize)
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\psychopy\\sound\\backend\_sounddevice.py", line 84, in getStream
> blockSize=blockSize)
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\psychopy\\sound\\backend\_sounddevice.py", line 128, in \_getStream
> device=defaultOutput)
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\psychopy\\sound\\backend\_sounddevice.py", line 159, in \_\_init\_\_
> callback=self.callback)
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\sounddevice.py", line 1373, in \_\_init\_\_
> \*\*\_remove\_self(locals()))
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\sounddevice.py", line 779, in \_\_init\_\_
> 'Error opening {0}'.format(self.\_\_class\_\_.\_\_name\_\_))
> File "C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\sounddevice.py", line 2571, in \_check
> raise PortAudioError(errormsg, err)
> sounddevice.PortAudioError: Error opening OutputStream: Invalid device \[PaErrorCode -9996\]
> \`\`\`
> 
> Do you have an idea on what is going wrong? Is there a bug? @peircej @mgeier @bastibe

> **[Massive sound lag using PsychoPy - Windows WASAPI for external sound card](https://discourse.psychopy.org/t/massive-sound-lag-using-psychopy-windows-wasapi-for-external-sound-card/5530/2)**
>
> It appears that the problem is raised because different instances of the device have the same name. Calling the appropriate instance by its ID at least enabled me playing a sound: sound.setDevice(10, kind='output') But, I still did not manage to...

Any help is highly appreciated.
