[PYTHON] Speaking Japanese with OpenJtalk (reading a text file)

I modified this program to read a text file aloud. Japanese utterances on OpenJtalk

program

kusamakura01.py


#! /usr/bin/python
#
#	kusamakura01.py
#
#						Nov/01/2020
#
# --------------------------------------------------------------------
import subprocess
import sys
# --------------------------------------------------------------------
def jtalk_proc(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())
	sys.stderr.write("*** wav is created ***\n")
	args = ['aplay','-q','open_jtalk.wav']
	print(args)
	subprocess.run(args)
#
# --------------------------------------------------------------------
sys.stderr.write("***start***\n")
file_in = sys.argv[1]
#
fp_in = open(file_in,encoding='utf-8')
lines = fp_in.readlines()
fp_in.close()
#
count = 0
line_out = ""
for line in lines:
	print(count,line)
	if 5 < count:
		break
	line_out += line[:-1]
	line_out += "  " 
	line_out += "  " 
	line_out += "  " 
	count += 1
#
print(line_out)
jtalk_proc(line_out)
#
sys.stderr.write("***End***\n")
# --------------------------------------------------------------------

Input data

in01.txt


Kusamakura
Natsume Soseki

While climbing Yamamichi, I thought like this.
If you work later If you let it go well, it will be washed away. It's a stubborn thing. Anyway, the human world is hard to live in.
When it becomes difficult to live, I want to move to a cheap place. When I find it difficult to live wherever I go, poetry is born and I can do it.

Execution method

./kusamakura01.py in01.txt

If you do the same with bash

#
perl -pe 's/\n/  /g' < in01.txt > tmp01.txt
#
open_jtalk \
        -x /var/lib/mecab/dic/open-jtalk/naist-jdic \
        -m /usr/share/hts-voice/mei/mei_normal.htsvoice \
        -r 1.0 \
        -ow ./out01.wav \
        tmp01.txt
#
aplay out01.wav
#

How to not create a wav file

perl -pe 's/\n/  /g' < in01.txt  \
 | open_jtalk \
	-x /var/lib/mecab/dic/open-jtalk/naist-jdic \
	-m /usr/share/hts-voice/mei/mei_normal.htsvoice \
	-r 1.0 \
	-ow /dev/stdout | aplay --quiet

Recommended Posts

Speaking Japanese with OpenJtalk (reading a text file)
Speaking Japanese with gTTS (reading a text file)
Speaking Japanese with OpenJtalk
Speak Japanese text with OpenJTalk + python
Create a large text file with shellscript
Convert a text file with hexadecimal values to a binary file
Export a gzip-compressed text file
Build a deb file with Docker
Create a file uploader with Django
Extract lines that match the conditions from a text file with python
Extract Japanese text from PDF with PDFMiner
Create a VM with a YAML file (KVM)
Read a character data file with numpy
Create a matrix with PythonGUI (text box)
I made a configuration file with Python
I want to display only different lines of a text file with diff
Replace the named entity in the read text file with a label (using GiNZA)
How to read a CSV file with Python 2/3
Create a GUI executable file created with tkinter
CRLF becomes LF when reading a Python file
Create a PDF file with a random page size
"Inline" Sublime Text plugin callbacks with a generator
Create a python3 build environment with Sublime Text3
I tried reading a CSV file using Python
Save the object to a file with pickle
Draw a graph with matplotlib from a csv file
Extract zip with Python (Japanese file name support)
Create a Photoshop format file (.psd) with python
Wav file generation from numeric text with python
Read line by line from a file with Python
I want to write to a file with Python
Open a file dialog with a python GUI (tkinter.filedialog)
Create a cylinder with open3d + STL file output
When reading a csv file with read_csv of pandas, the first column becomes index
Japanese with matplotlib
[Blender] Complement Blender's Python API with a text editor
Make a function to describe Japanese fonts with OpenCV
Type after reading an excel file with pandas read_excel
I tried reading data from a file using Node.js.
Run a Python file with relative import in PyCharm
[Python] Create a Tkinter program distribution file with cx_Freeze
Create a Japanese OCR environment with Anaconda (tesseract + pyocr)
Set up a Python development environment with Sublime Text 2
Create a 2d CAD file ".dxf" with python [ezdxf]
When reading an image with SimpleITK, there is a problem if there is Japanese in the path