×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
tts_server.py
#! /usr/bin/env python3 import socketserver import subprocess SPEED = 1.8 PITCH = 300 VOLUME = 1.0 DICDIR = "/var/lib/mecab/dic/open-jtalk/naist-jdic/" HTSVOICE = "/opt/voice/mei_normal.htsvoice" CMD = "open_jtalk -r {0} -p {1} -jm {2} -x {3} -m {4} -ow /dev/stdout \ | aplay --quiet".format(SPEED, PITCH, VOLUME, DICDIR, HTSVOICE) class TTS_Server(socketserver.BaseRequestHandler): """ gstreamerのudpsink(5004)から文字列を受け取って open_jtalkのstdinに渡すUDPServer """ def handle(self): data = self.request[0] with subprocess.Popen(CMD, shell=True, stdin=subprocess.PIPE).stdin as stream: stream.write(data) print(str(data,"utf8")) if __name__ == "__main__": HOST, PORT = "localhost", 5004 print("server listen {0}:{1}".format(HOST, PORT)) server = socketserver.UDPServer((HOST, PORT), TTS_Server) server.serve_forever() # 2015/05/11 とりあえず動いた
gst-srt-tts.sh
#!/bin/sh WIDTH=960 VIDEO_HEIGHT=540 SUBTITLE_HEIGHT=100 FONT_NAME="selif" VIDEO_PATH="$1" SRT_PATH="${1%.*}.srt" gst-launch-1.0 videomixer name=mix sink_1::ypos=${VIDEO_HEIGHT} ! xvimagesink \ filesrc location="${VIDEO_PATH}" ! queue ! decodebin name=decode \ decode. ! videoscale ! video/x-raw,width=${WIDTH},height=${VIDEO_HEIGHT} ! mix.sink_0 \ decode. ! pulsesink \ videotestsrc pattern=black ! video/x-raw,width=${WIDTH},height=${SUBTITLE_HEIGHT} \ ! subtitleoverlay name=overlay font-desc="${FONT_NAME}" ! mix.sink_1 \ filesrc location="${SRT_PATH}" ! queue \ ! subparse subtitle-encoding=UTF-8 ! tee name=srt ! overlay. \ srt. ! udpsink
使い方
tts_serverを起動しておく
python3 tts_server.py
別の terminal を開いて test.mp4 test.srt がある場所で
gst-srt-tts.sh test.mp4
で日本語字幕の表示と読み上げをしながら動画再生する
参考にしたところ
PR
コメント