Raspberry Pi2でミクさんに喋らせてみた(Python + OpenJTalk)

Facebook にシェア
Pocket
LINEで送る
このエントリーを Google ブックマーク に追加

昨日のシェルスクリプトをPythonで実行させただけ。

前提

Raspberry Pi2でミクさんに喋らせてみた(OpenJTalk) を設定済み。
LinuxMint(Ubuntu) pyenvをホームディレクトリに構築 でPythonの環境構築した。

以下コード

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

class Talk(object):

    def create_wav(self, text):

        open_jtalk = ["open_jtalk"]
        td = ["-td", "/usr/share/hts-voice/miku/tree-dur.inf"]
        tf = ["-tf", "/usr/share/hts-voice/miku/tree-lf0.inf"]
        tm = ["-tm", "/usr/share/hts-voice/miku/tree-mgc.inf"]
        md = ["-md", "/usr/share/hts-voice/miku/dur.pdf"]
        mf = ["-mf", "/usr/share/hts-voice/miku/lf0.pdf"]
        mm = ["-mm", "/usr/share/hts-voice/miku/mgc.pdf"]
        dm = ["-dm", "/usr/share/hts-voice/miku/mgc.win1"]
        dm += ["-dm", "/usr/share/hts-voice/miku/mgc.win2"]
        dm += ["-dm", "/usr/share/hts-voice/miku/mgc.win3"]
        df = ["-df", "/usr/share/hts-voice/miku/lf0.win1"]
        df += ["-df", "/usr/share/hts-voice/miku/lf0.win2"]
        df += ["-df", "/usr/share/hts-voice/miku/lf0.win3"]
        dl = ["-dl", "/usr/share/hts-voice/miku/lpf.win1"]
        ef = ["-ef", "/usr/share/hts-voice/miku/tree-gv-lf0.inf"]
        em = ["-em", "/usr/share/hts-voice/miku/tree-gv-mgc.inf"]
        cf = ["-cf", "/usr/share/hts-voice/miku/gv-lf0.pdf"]
        cm = ["-cm", "/usr/share/hts-voice/miku/gv-mgc.pdf"]
        k = ["-k", "/usr/share/hts-voice/miku/gv-switch.inf"]
        s = ["-s", "16000"]
        a = ["-a", "0.05"]
        u = ["-u", "0.0"]
        jm = ["-jm", "1.0"]
        jf = ["-jf", "1.0"]
        jl = ["-jl", "1.0"]
        x = ["-x", "/var/lib/mecab/dic/open-jtalk/naist-jdic"]
        ow = ["-ow", "/tmp/jtalk.wav"]

        cmd = open_jtalk + td + tf + tm + md + mf + mm + dm + df
        cmd += dl + ef + em + cf + cm + k + s + a + u + jm
        cmd += jf + jl + x + ow

        c = subprocess.Popen(cmd, stdin=subprocess.PIPE)
        c.stdin.write(text.encode("utf-8"))
        c.stdin.close()
        c.wait()

    def play_wav(self):

        aplay = ['aplay']
        q = ["-q", "/tmp/jtalk.wav"]

        cmd = aplay + q
        wr = subprocess.Popen(cmd)


if __name__ == '__main__':

    talk  = Talk()
    talk.create_wav("あいうえお")
    talk.play_wav()

コマンドのオプション部分はiniファイルにするとか工夫の余地はあるとは思う。

Related posts

One Thought to “Raspberry Pi2でミクさんに喋らせてみた(Python + OpenJTalk)”

  1. […] Raspberry Pi2でミクさんに喋らせてみた(Python + OpenJTalk) や Raspberry Piにミクさんボイスでタイムラインをしゃべらせた(OpenJTalk) のPythonのオプションも上のように変更すればいい。省略。 […]

コメントを残す