I modified this program to read a text file aloud. Japanese utterances on OpenJtalk
program
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("***start***\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("***End***\n")
# --------------------------------------------------------------------
Input data
in01.txt
Kusamakura
Natsume Soseki
While climbing Yamamichi, I thought like this.
If you work later If you let it go well, it will be washed away. It's a stubborn thing. Anyway, the human world is hard to live in.
When it becomes difficult to live, I want to move to a cheap place. When I find it difficult to live wherever I go, poetry is born and I can do it.
Execution method
./kusamakura01.py in01.txt
If you do the same with 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
#
How to not create a wav file
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
Recommended Posts