| Reference | Downloads | Github

UnicodeDecodeError when using the "sound" component

Hi everyone,

I have created a well-working experiment that I was able to run on any machine I tried, no problems there. After a bit, I have decided to add a sound component to it (what particular sound would play changes every repeat) and, again, all worked without an issue. However, when I tried to run it on a different machine (same OS - Windows - just a different version, 7 instead of 10), I got the following error:

File “D:…\”, line 80, in
Zvuk_instrukce = sound.Sound(‘A’, secs=-1)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\”, line 680, in init
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\”, line 1028, in initPyo
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\”, line 282, in flush
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\”, line 268, in flush
target.write(formatted[thisEntry] + ‘\n’)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\”, line 188, in write
File “C:\Program Files (x86)\PsychoPy2\lib\”, line 706, in write
return self.writer.write(data)
File “C:\Program Files (x86)\PsychoPy2\lib\”, line 369, in write
data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe1 in position 32: ordinal not in range(128)

apparently, this issue is only related to the sound component, since when I commented out all the code related to the sound component, the error goes away. I’m having a hard time figuring out why, though - I am not using any non-ascii characters in the component name or anything like that. The machine where the code was created (partially using the Builder) has an EN locale, the machine having issues has CZ locale. The same thing happened on yet another machine with CZ locale.

Any clues as to what might be causing this? Thanks.

My guess here is that your sound device has a unicode character in its name on the CZ locale computer and this is causing an error as the log file is written (because it refers to the audio device being used)
@hsogo12600 made a fix to this issue here:

so it might be that you can fetch new copies of

These will be included in the next release.

Dear Jon,

thanks! Where do I replace the files, though? Although I have the newest stable version of PsychoPy, there is no /sound directory in the respective lib/site-packages/psychopy directory (I guess the /sound directory is planned to be there in the next release). I tried to replace the init file in app/builder/components/sound, but that turned out not be a good idea.

Thanks again,

Dear Adam,

i have the exact same problem after the reconfig of my computer.
Did you succeed somehow with your sound stimuli?

Thank you!

I found the solution on my computer. I have to start Psychopy2 with Administrator rights, that way the sound works just fine.