当前位置: 首页 > 工具软件 > Jtalk > 使用案例 >

open_jtalk实现日语语音系统

薛扬
2023-12-01
#coding: utf-8
import subprocess
from datetime import datetime
import winsound

def jtalk(t):

    OPENJTALK_BINPATH = 'C://open_talk/open_jtalk-1.11/bin'
    OPENJTALK_DICPATH = 'C://open_talk/open_jtalk-1.11/dic'
    OPENJTALK_VOICEPATH = 'C://open_talk/open_jtalk-1.11/voice/nitech_jp_atr503_m001.htsvoice'
    open_jtalk=[OPENJTALK_BINPATH + '/open_jtalk.exe']
    mech=['-x',OPENJTALK_DICPATH]
    htsvoice=['-m',OPENJTALK_VOICEPATH]
    speed=['-r','1.0']
    outwav=['-ow','open_jtalk.wav']
    cmd=open_jtalk+mech+htsvoice+speed+outwav

    c = subprocess.Popen(cmd,stdin=subprocess.PIPE)

    # convert text encoding from utf-8 to shitf-jis
    c.stdin.write(t.encode('shift-jis'))
    c.stdin.close()
    c.wait()

    winsound.PlaySound('open_jtalk.wav', winsound.SND_FILENAME)


def say_datetime(): 
    text = "今晩は月綺麗ですね"
    print (text)
    jtalk(text)

if __name__ == '__main__':
    say_datetime()

结果:成功输出语音文件。
OPENJTALK_VOICEPATH ,可以切换模型。

配置:https://blog.csdn.net/CSDN_71560364126/article/details/102510419
下载:https://sourceforge.net/projects/open-jtalk/

 类似资料: