0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OpenJtalk で日本語の発話 (テキストファイルの読み上げ)

Last updated at Posted at 2020-11-01

こちらのプログラムを改造して、テキストファイルを読み上げるようにしました。
OpenJtalk で日本語の発話

プログラム

kusamakura01.py
#! /usr/bin/python
#
#	kusamakura01.py
#
#						Nov/01/2020
#
# --------------------------------------------------------------------
import subprocess
import sys
# --------------------------------------------------------------------
def jtalk_proc(tt):
	open_jtalk=['open_jtalk']
	mech=['-x','/var/lib/mecab/dic/open-jtalk/naist-jdic']
	htsvoice=['-m','/usr/share/hts-voice/mei/mei_normal.htsvoice']
	speed=['-r','1.0']
	outwav=['-ow','open_jtalk.wav']
	cmd=open_jtalk+mech+htsvoice+speed+outwav
	subprocess.run(cmd,input=tt.encode())
	sys.stderr.write("*** wav is created ***\n")
	args = ['aplay','-q','open_jtalk.wav']
	print(args)
	subprocess.run(args)
#
# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
file_in = sys.argv[1]
#
fp_in = open(file_in,encoding='utf-8')
lines = fp_in.readlines()
fp_in.close()
#
count = 0
line_out = ""
for line in lines:
	print(count,line)
	if 5 < count:
		break
	line_out += line[:-1]
	line_out += "  " 
	line_out += "  " 
	line_out += "  " 
	count += 1
#
print(line_out)
jtalk_proc(line_out)
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------

入力データ

in01.txt
草枕
夏目漱石

やまみちを登りながら、こう考えた。
ちに働けばかどが立つ。じょうにさおさせば流される。意地をとおせばきゅうくつだ。とかくに人の世は住みにくい。
住みにくさがこうじると、安い所へ引き越したくなる。どこへ越しても住みにくいとさとった時、詩が生れて、えが出来る。

実行方法

./kusamakura01.py in01.txt

bash で同じことを行う場合

#
perl -pe 's/\n/  /g' < in01.txt > tmp01.txt
#
open_jtalk \
        -x /var/lib/mecab/dic/open-jtalk/naist-jdic \
        -m /usr/share/hts-voice/mei/mei_normal.htsvoice \
        -r 1.0 \
        -ow ./out01.wav \
        tmp01.txt
#
aplay out01.wav
#

wav ファイルを作成しない方法

perl -pe 's/\n/  /g' < in01.txt  \
 | open_jtalk \
	-x /var/lib/mecab/dic/open-jtalk/naist-jdic \
	-m /usr/share/hts-voice/mei/mei_normal.htsvoice \
	-r 1.0 \
	-ow /dev/stdout | aplay --quiet
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?