Help us understand the problem. What is going on with this article?

macでコードから音声を喋らせる (eSpeak, OpenJTalk)

More than 3 years have passed since last update.

導入めちゃめちゃ簡単でした。homebrewありがとう。

espeak: 英語

インストール & 実行

$ brew install espeak
$ espeak "hello world"

open-jtalk: 日本語

インストール

$ brew install open-jtalk

これだけで
辞書ファイル(/usr/local/Cellar/open-jtalk/1.10_1/dic/)も
音声ファイル(/usr/local/Cellar/open-jtalk/1.10_1/voice/)も入りました。

実行

女性ボイス: mei_normal.htsvoice

$ echo "吾輩は猫である。名前はまだ無い。どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。" > 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

男性ボイス: 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

pythonから実行。以下の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月%s日、%s時%s分%s秒' % (d.month, d.day, d.hour, d.minute, d.second)
    jtalk(text)

if __name__ == '__main__':
    say_datetime()
$ python jtalk.py

python モジュールとして利用

$ python
>>> import jtalk
>>> jtalk.jtalk ("ロウセイのリチョウは博学サイエイ、天宝のマツネン、若くして名をコボウに連ね、ついでコウナンイに補せられたが、性、狷介、自ら恃むところ頗る厚く、センリに甘んずるを潔しとしなかった。")

参考: http://qiita.com/kkoba84/items/b828229c374a249965a9

msrks
Computer Scienceと物理が好きです
http://msrks.github.io
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした