-
Notifications
You must be signed in to change notification settings - Fork 61
/
text2wave
executable file
·43 lines (36 loc) · 1.41 KB
/
text2wave
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
import rospkg
import rospy
import sys
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='')
parser.add_argument('-eval', '--evaluate')
parser.add_argument('-o', '--output')
parser.add_argument('text')
args = parser.parse_args()
input_file = args.text
jptext_file = "/tmp/_voice_text_%s.txt"%os.getpid()
output_file = "/tmp/_voice_text_%s.wav"%os.getpid()
phont_file = "aq_f1c.phont"
phont_file ="%s/phont/%s"%(rospkg.RosPack().get_path("aques_talk"), phont_file)
if args.output is not None:
output_file = args.output
if not os.path.exists(input_file):
rospy.logerr("%s not found"%input_file)
sys.exit(1)
if args.evaluate in ['(en)']:
os.system("/usr/bin/text2wave %s > %s"%(input_file, output_file))
sys.exit(0)
# escape invalid code
os.system("nkf -j %s | kakasi -JH | nkf -w | \
sed -e 's/,/、/g' | sed -e 's/,/、/g' | \
sed -e 's/./。/g' | sed -e 's/\./。/g' | \
sed -e 's/\([a-zA-Z]\+\)/<ALPHA VAL=\\1>/g' | \
sed -e 's/\([0-9]\+\)/<NUMK VAL=\\1>/g' > \
%s"%(input_file, jptext_file))
os.system("cat %s 1>&2"%(jptext_file))
os.system("rosrun aques_talk SampleTalk -p %s -o %s %s"%(phont_file, output_file, jptext_file))
os.remove(jptext_file)