1
2

Windowsナレータープログラム

Last updated at Posted at 2023-12-24

Windowsの読上げをpythonで使ったナレータープログラム

Windows用のナレータープログラムをpythonで作ってみました。

工夫点

読みと表示に分けて読み間違える部分をひらがなやカタカナで指定できるようにした点。

必要なもの

PySimpleGUI と Win32com ライブラリを使っているので
pip list で確認して入っていなければ
pip install PySimpleGUI
pip install win32com
でインストールしてください。

ソース(自由に改修してください)

#
import PySimpleGUI as psg
import win32com.client as wc

spk = wc.Dispatch('SAPI.SpVoice')

# ここにナレーションを入れます。(’よみ’,'表示')の順で書きます
mess = [
    ('読みには読めない漢字の部分を平仮名で入れます。','読みには読めない漢字の部分を平仮名で入れます。'),
    ('読みと表示に分けることで正確に発音できます。','読みと表示に分けることで正確に発音できます。')
]
dispnum=0

wlay = [[psg.Multiline(default_text=mess[0][1],size=(40,10),border_width=2,font=("",15),key='MText',disabled=True)],
        [psg.Button('Next',key='Next'),psg.Button('Top',key='Top'),psg.Button('終了',key='END')]]

win = psg.Window('ナレーター',wlay)
while True:
    ev,val = win.read()
    if ev in ('END',None):
        break
    if ev == 'Next':
        dispnum+=1
        if dispnum >= len(mess):
            dispnum=len(mess)-1
    if ev == 'Top':
        dispnum=0
    win['MText'].Update(mess[dispnum][1])
    spk.Speak(mess[dispnum][0])

win.close()
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2