显示在Ubuntu和Windows上的方法。对不起,Mac没有环境。
在Ubuntu 14.04 LTS上与OpenJTalk Python交谈
打开JTalk设置
使用
终奌站
1 | $ sudo apt-get install open-jtalk open-jtalk-mecab-naist-jdic hts-voice-nitech-jp-atr503-m001 |
音频文件设置
语音数据从MMDAgent转移。
终奌站
1 | $ 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 |
接下来,提取
终奌站
1 | $ unzip MMDAgent_Example-1.6.zip MMDAgent_Example-1.6/Voice/* |
将文件复制到hts-voice-nitech
所在的位置
终奌站
1 | $ sudo cp -r MMDAgent_Example-1.6/Voice/mei/ /usr/share/hts-voice |
使用Python
播放
http://raspi.seesaa.net/article/415530289.html
我被允许提及。
将以下代码另存为
jtalk.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #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月%s日、%s時%s分%s秒' % (d.month, d.day, d.hour, d.minute, d.second) jtalk(text) if __name__ == '__main__': say_datetime() |
在执行测试中,
终奌站
1 | $ python jtalk.py |
希望能说出当前时间
从其他模块使用时,
from_module_1.py
1 2 3 4 | #coding: utf-8 import jtalk jtalk.jtalk('何か話してください') |
在Windows上设置Open JTalk
在Ubuntu上,我可以通过
在Windows上,您可以自行构建。
获取源代码
从
http://open-jtalk.sourceforge.net/
获取OpenJTalk 1.09
- http://downloads.sourceforge.net/open-jtalk/open_jtalk-1.09.tar.gz
从http://hts-engine.sourceforge.net/下载
编译所需的语音合成库hts_engineAPI。
- http://downloads.sourceforge.net/hts-engine/hts_engine_API-1.10.tar.gz
如果
使用Visual Studio
进行编译
启动Visual Studio的命令工具。键入
首先,从hts_engine_API-1.10进行编译。
指令
1 2 3 | cd c:\temp\open_jtalk-1.09\hts_engine_API-1.10 nmake /f Makefile.mak nmake /f Makefile.mak install |
如果
成功编译,将在
接下来,编译open_jtalk。
指令
1 2 3 | cd c:\temp\open_jtalk-1.09 nmake /f Makefile.mak nmake /f Makefile.mak install |
当要转换字典的字符串显示在末尾时,这些字符会出现乱码。
我很好奇,但是如果您担心的话,Open JTalk有一个预建的字典,所以
您也可以使用它。
这将生成
获取语??音数据
来自MMDAgent
https://sourceforge.net/projects/mmdagent/files/MMDAgent_Example/MMDAgent_Example-1.6/
从下载MMDAgent_Example-1.6.zip,并将Voice / mei / *。htvoice复制到c:\\\\ open_jtalk \\\\ bin \\\\。
执行测试
假设在c:\\\\ open_jtalk \\\\ bin
中创建了输入日语的文件作为input.txt。
指令
1 2 | c:\open_jtalk\bin open_jtalk -m mei_normal.htsvoice -x ../dic -ow output.wav input.txt |
尝试运行
。现在,如果在同一文件夹中创建了output.wav,则
从资源管理器中双击以查看其是否播放。
在Windows
上使用Python运行OpenJTalk
ubuntu使用aplay命令播放文件。在Windows上,
使用winsound模块。另外,由于在Windows上的此编译中的字典生成是shift-jis,因此在将其传递给stdin时,有必要将其编码从python的内部编码转换为。
在下面,将示例程序另存为c:\\\\ open_jtalk \\\\ bin中的jtalk.py。
jtalk.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #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月%s日、%s時%s分%s秒' % (d.month, d.day, d.hour, d.minute, d.second) print(text) jtalk(text) if __name__ == '__main__': say_datetime() |
执行此操作。我安装了PythonPython,所以
指令
1 | python jtalk.py |
使用
说出当前日期和时间。
用作Python模块
时
从命令提示符执行python时,日语字符串仍为Shift-JIS或不统一。
因此,在输入日语时,请在开头添加
from_module_2.py
1 2 3 | import jtalk jtalk.jtalk(u'日本語を話します') |