[PYTHON] Speak voice from code on mac (eSpeak, OpenJTalk)

It was really easy to introduce. homebrew Thank you.

espeak: english

Install & run

$ brew install espeak
$ espeak "hello world"

open-jtalk: Japanese

Installation

$ brew install open-jtalk

This alone Dictionary files (/usr/local/Cellar/open-jtalk/1.10_1/dic/) The audio file (/usr/local/Cellar/open-jtalk/1.10_1/voice/) is also included.

Run

Female voice: mei_normal.htsvoice

$ echo "I am a cat. There is no name yet. I have no idea where I was born. I remember only crying in a dim and damp place. I saw human beings for the first time here." > sample.txt
$ open_jtalk \
-x /usr/local/Cellar/open-jtalk/1.10_1/dic \
-m /usr/local/Cellar/open-jtalk/1.10_1/voice/mei/mei_normal.htsvoice \
-ow out.wav sample.txt
$ afplay out.wav

Male voice: nitech_jp_atr503_m001.htsvoice

$ open_jtalk \
-x /usr/local/Cellar/open-jtalk/1.10_1/dic \
-m /usr/local/Cellar/open-jtalk/1.10_1/voice/m100/nitech_jp_atr503_m001.htsvoice \
-ow out.wav sample.txt
$ afplay out.wav

Run from python. Create and save the following jtalk.py.

jtalk.py


# coding: utf-8
import subprocess
from datetime import datetime

def jtalk(t):
    open_jtalk = ['open_jtalk']
    mech = ['-x', '/usr/local/Cellar/open-jtalk/1.10_1/dic']
    htsvoice = ['-m', '/usr/local/Cellar/open-jtalk/1.10_1/voice/mei/mei_normal.htsvoice']
    speed = ['-r', '1.0']
    outwav = ['-ow', 'out.wav']
    cmd = open_jtalk + mech + htsvoice + speed + outwav
    c = subprocess.Popen(cmd, stdin=subprocess.PIPE)
    c.stdin.write(t)
    c.stdin.close()
    c.wait()
    aplay = ['afplay', 'out.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()
$ python jtalk.py

Used as a python module

$ python
>>> import jtalk
>>> jtalk.jtalk ("Rosei's Richou was joined by Gakusai Saiei, Tenpo Matsunen, and Kobo at a young age, and was then supplemented by Kounani.")

Reference: http://qiita.com/kkoba84/items/b828229c374a249965a9

Recommended Posts

Speak voice from code on mac (eSpeak, OpenJTalk)
OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)
Call C / C ++ from Python on Mac
Update Python on Mac from 2 to 3
Install PostgreSQL from source code on CentOS
python on mac
Preferences to generate animated GIFs from Python on Mac
Read QR code from image file with Python (Mac)