私は、単語がスクリーン上に1つずつ提示される読み上げ実験をコーディングしました。これらの単語は、ドイツ語の単語を音節に分割した.txtファイル(UTF-8)から取り込んでいます。音節間の分割は「 - 」によって行われます。だから、.TXTファイルには、このような言葉が含まれます。Umlautは余分な文字としてカウントされます。これをPythonで覆すには?
ツヴァイ-TERダイNERクンスト-LI-CHEソーセージ・チェンのプログラムの目的は、正確になして、単語を表示することです' - ':
zweiterディーナーkünstlicheWürstchen
ウムラウトのすべてが含まれていない単語がfolloを使用して、細かい行きますウイングコード:
# Strip newlines and split into syllables syllables = word.strip().split('-') word = ''.join(syllables) # Index for keeping track in which color to display the next syllable color_index = 0 letter_count = 0 for syllable in syllables: # Pad the syllable for spaces for every letter of the word that is not part of this syllable # This ensures proper placement of the syllable on the screen padded_syllable = ' ' * letter_count + syllable + ' ' * (len(word) - letter_count - len(syllable)) text = visual.TextStim( win=window, text=padded_syllable, font='Courier New', color=colors[color_index], colorSpace='rgb', units='pix', pos=(0, -234),height =68, ) text.draw() letter_count += len(syllable))
はしかし、手紙はウムラウトが含まれている場合ワード部品間の間隔がうまくいかない場合、この手紙は2としてカウントしているようです。 「künst-li-che」は「künstli-che」と表示され、「künstliche」になります。
Umlautで手紙を1文字として数える方法はありますか?
https://stackoverflow.com/questions/8056496/python-get-unicode-string-sizeを結合を使用してあなたが記述問題を得ることはありません – 101