Shows the method on Ubuntu and Windows. I'm sorry that Mac has no environment.
Install open-jtalk (1.07) with ʻapt-get`.
Terminal
$ sudo apt-get install open-jtalk open-jtalk-mecab-naist-jdic hts-voice-nitech-jp-atr503-m001
The mecab
dictionary is installed in/ var / lib / mecab / dic / open-jtalk / naist-jdic /
.
Voice data is diverted from MMDAgent. The MMDAgent_Example-1.6.zip
is 11MB.
Terminal
$ wget https://sourceforge.net/projects/mmdagent/files/MMDAgent_Example/MMDAgent_Example-1.6/MMDAgent_Example-1.6.zip/download -O MMDAgent_Example-1.6.zip
Then extract the .htsvoice
file
Terminal
$ unzip MMDAgent_Example-1.6.zip MMDAgent_Example-1.6/Voice/*
Copy the file to the same location as hts-voice-nitech
Terminal
$ sudo cp -r MMDAgent_Example-1.6/Voice/mei/ /usr/share/hts-voice
http://raspi.seesaa.net/article/415530289.html I was allowed to refer to.
Save the following code as jtalk.py
in a file.
jtalk.py
#coding: utf-8
import subprocess
from datetime import datetime
def jtalk(t):
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
c = subprocess.Popen(cmd,stdin=subprocess.PIPE)
c.stdin.write(t.encode())
c.stdin.close()
c.wait()
aplay = ['aplay','-q','open_jtalk.wav']
wr = subprocess.Popen(aplay)
def say_datetime():
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()
In the execution test
Terminal
$ python jtalk.py
Hopefully speak the current time When using from other modules
from_module_1.py
#coding: utf-8
import jtalk
jtalk.jtalk('Tell me something')
On Ubuntu, I could install it smoothly by doing ʻapt-get`, On Windows you build it yourself.
Get OpenJTalk 1.09 from http://open-jtalk.sourceforge.net/
Download the speech synthesis library hts_engineAPI required for compilation from http://hts-engine.sourceforge.net/
If you expand ʻopen_jtalk-1.09.tar.gz to
c: \ temp \ open_jtalk-1.09, then
hts_engine_API-1.10.tar.gz is
c: \ temp \ open_jtalk-1.09 \ hts_engine_API- Expanding to 1.10` will reduce problems when compiling.
Launch the command tool in Visual Studio. Type nmake
to make sure it works.
First, compile from hts_engine_API-1.10.
cmd
cd c:\temp\open_jtalk-1.09\hts_engine_API-1.10
nmake /f Makefile.mak
nmake /f Makefile.mak install
If it compiles successfully, a file will be created in c: \ hts_engine_API
.
Next, compile open_jtalk.
cmd
cd c:\temp\open_jtalk-1.09
nmake /f Makefile.mak
nmake /f Makefile.mak install
When the character string to convert the dictionary is displayed near the end, the characters are garbled I'm curious, but if you're worried, Open JTalk has a prebuilt dictionary, so You can also use it.
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 .
Assuming that a file with Japanese input is created as input.txt in c: \ open_jtalk \ bin
cmd
c:\open\jtalk\bin
open_jtalk -m mei_normal.htsvoice -x ../dic -ow output.wav input.txt
I will try to execute. Now, if output.wav is created in the same folder, put it Double-click from Explorer to see if it plays.
In ubuntu, I used the aplay command to play the file. On Windows Use the winsound module. Also, since the dictionary generation in this compilation on Windows was shift-jis, it is necessary to convert the encoding from the internal encoding of python when passing it to stdin.
Below, save the sample program as jtalk.py in c: \ open_jtalk \ bin.
jtalk.py
#coding: utf-8
# call OpenJTalk for windows
import subprocess
import winsound
from datetime import datetime
def jtalk(t):
# depend on your install folder
OPENJTALK_BINPATH = 'c:/open_jtalk/bin'
OPENJTALK_DICPATH = 'c:/open_jtalk/dic'
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():
d = datetime.now()
text = '%s month%s day,%s time%s minutes%s seconds' % (d.month, d.day, d.hour, d.minute, d.second)
print(text)
jtalk(text)
if __name__ == '__main__':
say_datetime()
Do this. I have anaconda python installed, so
cmd
python jtalk.py
Then, speak the current date and time.
jtalk.py
is saved in utf-8 encoding.
When executing python from the command prompt, the Japanese character string is still Shift-JIS or is not unified.
Therefore, when entering Japanese, add ʻu" Japanese " and ʻu
to indicate that it is utf-8.
from_module_2.py
import jtalk
jtalk.jtalk(u'I'll speak Japanese')
Recommended Posts