Speaking Japanese with OpenJtalk

I confirmed the same thing on Ubuntu 20.10. Speak Japanese text with OpenJTalk + python

The environment I confirmed

$ uname -a
Linux iwata 5.8.0-26-generic #27-Ubuntu SMP Wed Oct 21 22:29:16 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ python --version
Python 3.8.6
  1. Library installation
sudo apt install open-jtalk open-jtalk-mecab-naist-jdic hts-voice-nitech-jp-atr503-m001
  1. Audio file setup
get https://sourceforge.net/projects/mmdagent/files/MMDAgent_Example/MMDAgent_Example-1.6/MMDAgent_Example-1.6.zip/download -O MMDAgent_Example-1.6.zip
unzip MMDAgent_Example-1.6.zip MMDAgent_Example-1.6/Voice/*
sudo cp -r MMDAgent_Example-1.6/Voice/mei/ /usr/share/hts-voice
  1. Playback with Python

jtalk.py


#! /usr/bin/python
#
import subprocess
from datetime import datetime

def jtalk(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())
    aplay = ['aplay','-q','open_jtalk.wav']
    subprocess.run(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()
#

Run

./jtalk.py

Say the time and open_jtalk.wav will be created.

Play wav files

$ aplay open_jtalk.wav 
Playing WAVE'open_jtalk.wav' : Signed 16 bit Little Endian,Rate 48000 Hz,monaural

Sample program

ex01.py


#! /usr/bin/python
#
import jtalk

jtalk.jtalk('Hello')
#

ex02.py


#! /usr/bin/python
#
import jtalk

text_aa = 'A person had a donkey.'
text_aa += 'For a long time, this donkey has been rushing to bring wheat to the watermill.'

#
jtalk.jtalk(text_aa)
#

Recommended Posts

Speaking Japanese with OpenJtalk
Speak Japanese text with OpenJTalk + python
Japanese with matplotlib
Speaking Japanese with gTTS (reading a text file)
Japanese input with pyautogui
Send Japanese email with Python3
Japanese morphological analysis with Python
Draw Japanese with matplotlib on Ubuntu
[Natural language processing] Preprocessing with Japanese
Japanese speech synthesis starting with Tacotron2
Using Japanese with Rodeo's IPython @ Windows
I can't use Japanese with pyperclip
Easy Japanese font setting with matplotlib
[Note] Japanese characters are garbled with atom-runner
Generate Japanese test data with Python faker
Make Raspberry Pi speak Japanese using OpenJtalk
Put Japanese fonts in images with Colaboratory
Download Japanese stock price data with python
Notes on doing Japanese OCR with Python
Extract Japanese text from PDF with PDFMiner
How to use Japanese with NLTK plot
Display Japanese graphs with VS Code + matplotlib
How to display python Japanese with lolipop
[Python] Let's make matplotlib compatible with Japanese
How to enter Japanese with Python curses