Windows10 it was to try the OpenJTalk in, but the necessary environment to be for anyone because it was trimmed from scratch Make a note. As the title says, I will explain from environment construction to how to speak Japanese with Python.
On Windows, you need to build it yourself to run OpenJTalk, so prepare the environment.
This is not the main subject, so I will save it.
Start the command prompt and execute the following two commands.
cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build
vcvarsall.bat x64
If you try to execute the nmake
command at the command prompt and you get an error that the command cannot be executed (an error that the command is not recognized), you need to put the path of nmake.exe
in the environment variable. (I had to pass it)
I was able to take the following pass.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64
From here, I referred to the site of here. Thank you.
First, get OpenJTalk 1.09. Select from here, but it will be downloaded immediately at the link below.
http://downloads.sourceforge.net/open-jtalk/open_jtalk-1.09.tar.gz
Select the speech synthesis library hts_engineAPI required for compilation from here, but like OpenJTalk, it will be downloaded immediately with the following link.
http://downloads.sourceforge.net/hts-engine/hts_engine_API-1.10.tar.gz
Extract the downloaded ʻopen_jtalk-1.09.tar.gz Set it to
c: \ temp \ open_jtalk-1.09. Also, if the hts_engineAPI is expanded to
c: \ temp \ open_jtalk-1.09 \ hts_engine_API-1.10`, problems will be reduced when compiling.
Now that you can use nmake
at the command prompt, compile it.
First, start from hts_engine_API-1.10, so execute the following three commands. When completed, a file will be created in c: \ hts_engine_API.
cd c:\temp\open_jtalk-1.09\hts_engine_API-1.10
nmake /f Makefile.mak
nmake /f Makefile.mak install
Next, compile open_jtalk-1.09. Execute the following three commands. When completed, a file will be created in c: \ open_jtalk.
cd c:\temp\open_jtalk-1.09
nmake /f Makefile.mak
nmake /f Makefile.mak install
A garbled character string is displayed near the end, but it seems that you do not have to worry about it for the time being. Click here for details (https://qiita.com/kkoba84/items/b828229c374a249965a9)
This will generate c: \ open_jtalk \ bin \ open_jtalk.exe.
From MMDAgent https://sourceforge.net/projects/mmdagent/files/MMDAgent_Example/MMDAgent_Example-1.6/ Download MMDAgent_Example-1.6.zip from, and copy Voice / mei / *. Htvoice to c: \ open_jtalk \ bin . It is the data of four emotions of a girl named mei.
This completes the preparation.
Assuming that a file with Japanese input is created as input.txt in c: \ open_jtalk \ bin , Execute the following command.
cd c:\open\jtalk\bin
open_jtalk -m mei_normal.htsvoice -x ../dic -ow output.wav input.txt
If output.wav is created in the same directory, it is successful. Try double-clicking it to see if it plays. At this point, it may not work in Japanese due to the influence of encoding. Actually I didn't work.
Use the winsound module to run OpenJTalk from Python on Windows. Also, since the dictionary generation in this compilation on Windows was shift-jis, it is necessary to convert the encoding when passing from the internal encoding of python to stdin.
jtalk.py
#coding: utf-8
import subprocess
from datetime import datetime
import winsound
def jtalk(t):
# depend on your install folder
OPENJTALK_BINPATH = 'c:/open_jtalk/bin'
OPENJTALK_DICPATH = 'c:/open_jtalk/dic'
# VOICEPATH -> can change mei voice
OPENJTALK_VOICEPATH = 'c:/open_jtalk/bin/mei_normal.htsvoice'
open_jtalk=[OPENJTALK_BINPATH + '/open_jtalk.exe']
mech=['-x',OPENJTALK_DICPATH]
htsvoice=['-m',OPENJTALK_VOICEPATH]
speed=['-r','1.0']
outwav=['-ow','open_jtalk.wav']
cmd=open_jtalk+mech+htsvoice+speed+outwav
c = subprocess.Popen(cmd,stdin=subprocess.PIPE)
# convert text encoding from utf-8 to shitf-jis
c.stdin.write(t.encode('shift-jis'))
c.stdin.close()
c.wait()
# play wav audio file with winsound module
winsound.PlaySound('open_jtalk.wav', winsound.SND_FILENAME)
def say_datetime():
# get datetime and call jtalk
d = datetime.now()
text = '%s month%s day,%s time%s minutes%s seconds' % (d.month, d.day, d.hour, d.minute, d.second)
jtalk(text)
if __name__ == '__main__':
say_datetime()
Place it in any directory and start it with Python jtalk.py
. Of course, the startup method is free. It is successful if the computer speaks the date and time.
Call the above file (jtalk in jtalk.py) from the same directory (also free here). Also, since the argument is the character you want to speak, specify it. ʻU''` also specifies the encoding.
test.py
import jtalk
jtalk.jtalk(u'That's it')
that's all. It's been a long time, but thank you!
https://qiita.com/Gaccho/items/f748f59784ff68d7a474 https://qiita.com/kkoba84/items/b828229c374a249965a9
Recommended Posts