OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)

Introduction

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.

environment

Build environment preparation

On Windows, you need to build it yourself to run OpenJTalk, so prepare the environment.

Installing Visual Studio 2019 Community

This is not the main subject, so I will save it.

Installing Visual Studio 2019 Community Install Visual Studio 2019 from the [here](https://docs.microsoft.com/ja-jp/visualstudio/install/install-visual-studio?view=vs-2019) site. When the installer starts, check Desktop Development with C ++ and press Install. Please start once after the installation is completed. ↓ I referred to this site. Thank you. https://qiita.com/Gaccho/items/f748f59784ff68d7a474

Build settings

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

nmake settings

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

Install OpenJTalk

From here, I referred to the site of here. Thank you.

Obtaining source code OpenJTalk, hts_engineAPI

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 toc: \ 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.

Compile with nmake

Now that you can use nmake at the command prompt, compile it.

Compiling hts_engine_API-1.10.

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

Compile open_jtalk-1.09

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.

Get Voice data

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. image.png

This completes the preparation.

Open JTalk execution test

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.

Run OpenJTalk from Python

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.

Use as a Python module

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!

The site that I used as a reference

https://qiita.com/Gaccho/items/f748f59784ff68d7a474 https://qiita.com/kkoba84/items/b828229c374a249965a9

Recommended Posts

OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)
Python environment construction memo on Windows 10
Anaconda python environment construction on Windows 10
Speak Japanese text with OpenJTalk + python
python windows environment construction
Collecting information from Twitter with Python (Environment construction)
From Python environment construction to virtual environment construction with anaconda
Python environment construction (Windows10 + Emacs)
Build Python environment on Windows
Build python environment on windows
Python environment construction under Windows7 environment
[Tensorflow] Tensorflow environment construction on Windows 10
Get started with Python! ~ ① Environment construction ~
Let's get started with Python ~ Building an environment on Windows 10 ~
Install python2.7 on windows 32bit environment
Python environment construction memo on Mac
[Python3] Development environment construction << Windows edition >>
Python development environment construction on macOS
Python environment construction procedure memo using Docker on Windows10 Home
Environment construction of python3.8 on mac
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
Install Python development environment on Windows 10
pytorch @ python3.8 environment construction with pipenv
Getting started with Python 3.8 on Windows
OpenCV3 & Python3 environment construction on Ubuntu
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Environment construction
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Japanese file enumeration with Python2 system on Windows (5C problem countermeasure)
Everything from building a Python environment to running it on Windows
LaTeX and R (a little Python) environment construction with SublimeText3 (Windows)
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Run servo with Python on ESP32 (Windows)
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Python project environment construction procedure (for windows)
Building a Python 3.6 environment with Windows + PowerShell
Notes on doing Japanese OCR with Python
Creating a python virtual environment on Windows
VScode environment construction (Windows10, Python, C ++, C, Git)
Build Python environment with Anaconda on Mac
[Windows 10] "Deep Learning from scratch" environment construction
Let's get along with Python # 0 (Environment construction)
Windows + gVim + Poetry python development environment construction
Python on Windows
Python environment construction
python windows environment
Environment construction (python)
python environment construction
Python --Environment construction
Python environment construction
python environment construction
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
Steps to create a Python virtual environment with VS Code on Windows
Data integration from Python app on Windows to Amazon Redshift with ODBC
[Note] Python environment construction on rental server "CORESERVER"
Build python environment with pyenv on EC2 (ubuntu)
Simply build a Python 3 execution environment on Windows
Python explosive environment construction starting from zero (Mac)
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
Speak voice from code on mac (eSpeak, OpenJTalk)
Build a python environment with ansible on centos6
Python (Windows 10) Virtual Environment / Package with VS Code