pyaudioは、ここでダウンロードした。
オプションは、ここを参考にした。
まずまずの結果でした。
これを使えば、rrs読み上げソフトを作れそうだ。
import wave
import os
import pyaudio
if __name__ == "__main__":
voice = '/usr/local/share/hts_voice/mei_normal'
dic = '/usr/lib/open_jtalk/dic/utf-8' text = "ウブンツで、日本語テキストを読み上げさせてみた。"
import os
import pyaudio
if __name__ == "__main__":
voice = '/usr/local/share/hts_voice/mei_normal'
dic = '/usr/lib/open_jtalk/dic/utf-8' text = "ウブンツで、日本語テキストを読み上げさせてみた。"
opts = [
"-x " + dic + "/",
"-td " + voice + "/tree-dur.inf",
"-tm " + voice + "/tree-mgc.inf",
"-tf " + voice + "/tree-lf0.inf",
"-md " + voice + "/dur.pdf",
"-mm " + voice + "/mgc.pdf",
"-mf " + voice + "/lf0.pdf",
"-dm " + voice + "/mgc.win1",
"-dm " + voice + "/mgc.win2",
"-dm " + voice + "/mgc.win3",
"-df " + voice + "/lf0.win1",
"-df " + voice + "/lf0.win2",
"-df " + voice + "/lf0.win3",
"-dl " +voice + "/lpf.win1",
"-s 48000",
"-p 240", # 話速?
"-a 0.55", # 声質?
"-u 0.5", # 有声化・無声化?
"-jm 0.7", # 大小?
"-jf 0.5", # 抑揚?
"-jl 1.0",
"-l",
"-z 6000",
"-ow " + "out.wav",
"-em " + voice + "/tree-gv-mgc.inf",
"-ef " + voice + "/tree-gv-lf0.inf",
"-cm " + voice + "/gv-mgc.pdf",
"-cf " + voice + "/gv-lf0.pdf",
"-k " + voice + "/gv-switch.inf",
]
cmd = "open_jtalk "
for row in opts:
cmd += row + " "
cmd += "in.txt"
f = open("in.txt",'w')
f.write(text)
f.close()
os.system(cmd)
wf = wave.open("out.wav", "r")
# ストリームを開く
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
# チャンク単位でストリームに出力し音声を再生
chunk = 1024
data = wf.readframes(chunk)
while data != '':
stream.write(data)
data = wf.readframes(chunk)
stream.close()
p.terminate()
"-x " + dic + "/",
"-td " + voice + "/tree-dur.inf",
"-tm " + voice + "/tree-mgc.inf",
"-tf " + voice + "/tree-lf0.inf",
"-md " + voice + "/dur.pdf",
"-mm " + voice + "/mgc.pdf",
"-mf " + voice + "/lf0.pdf",
"-dm " + voice + "/mgc.win1",
"-dm " + voice + "/mgc.win2",
"-dm " + voice + "/mgc.win3",
"-df " + voice + "/lf0.win1",
"-df " + voice + "/lf0.win2",
"-df " + voice + "/lf0.win3",
"-dl " +voice + "/lpf.win1",
"-s 48000",
"-p 240", # 話速?
"-a 0.55", # 声質?
"-u 0.5", # 有声化・無声化?
"-jm 0.7", # 大小?
"-jf 0.5", # 抑揚?
"-jl 1.0",
"-l",
"-z 6000",
"-ow " + "out.wav",
"-em " + voice + "/tree-gv-mgc.inf",
"-ef " + voice + "/tree-gv-lf0.inf",
"-cm " + voice + "/gv-mgc.pdf",
"-cf " + voice + "/gv-lf0.pdf",
"-k " + voice + "/gv-switch.inf",
]
cmd = "open_jtalk "
for row in opts:
cmd += row + " "
cmd += "in.txt"
f = open("in.txt",'w')
f.write(text)
f.close()
os.system(cmd)
wf = wave.open("out.wav", "r")
# ストリームを開く
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
# チャンク単位でストリームに出力し音声を再生
chunk = 1024
data = wf.readframes(chunk)
while data != '':
stream.write(data)
data = wf.readframes(chunk)
stream.close()
p.terminate()