psychopy.org | Reference | Downloads | Github

How to display stimuli in Thai?

PsychoPy version 2021. 1.4)

What are you trying to achieve?:

I have constructed a fairly simple experiment involving the presentation of text stimuli (single words) with a rating task. The experiment has X number of trials per block for a total of 3 blocks. Everything is now working but I recently changed the text stimuli from English words to Thai words (in the Excel file) and then came across a coding problem. The experiment starts ok but stops just before the first trial. Everything works perfectly fine when I use English words instead.

I saw others have encountered presentation problems with other languages. Does anyone know a simple solution (I’m still quite a beginner).

What did you try to make it work?:
It works with English words but not with Thai words. With Thai words it stops the experiment.

I tried using the Textbox component as an alternative and it displays square symbols or squares and question makrs when using Thai words. Seems like it could be a font or encoding issue, but not sure how to fix this.

What specifically went wrong when you tried that?:

This is the message I get (partial message) when the experiment stops working (using the text box component to display the stimuli):

File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\base.py”, line 394, in get_glyphs
self.glyphs[c] = glyph_renderer.render(c)
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\win32.py”, line 432, in render
ord(text), ord(text), byref(abc)):
TypeError: ord() expected a character, but string of length 2 found

Experiment ended.

Hopefully there’s a simple solution.

Ben

Could you post the Thai phrases you’re trying to display? What is the font set to for the text box?

We have tests that we run which make sure a set of phrases work in corresponding fonts - I’ll add this to the test and can then see what’s causing this error :slight_smile:

Thanks a lot. I’m using Arial but tried a few other fonts without success.

This is a list of 10 single word items from one of the blocks:

ธนบัตร
วิทยุ
อัลมอลต์
เสาอากาศ
แอปเปิ้ล
ที่เขี่ยบุหรี่
หน่อไม้ฝรั่ง
อะโวคาโด
ขวาน
ขวดนม

When I try this, I don’t get any error, but the characters don’t display in Arial - they’re squares instead, as should happen when a font doesn’t have glyphs for a particular character. What happens when you try one of these fonts:

(you can download and install the fonts, or just refer to them by name and PsychoPy will get them from online)

If my theory is right, these shouldn’t cause an error as they’ll have those characters in their glyph set.

Brilliant! It works. I can also confirm that it works both ways as well: download and install the font or just type in the name of a preferred font from the google directory.

The next step is to get the experiment online.

For future reference, it only works with the textbox component (not with text).