test_rospeex_ss_tts.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 # import ros packages
00005 import rospy
00006 import unittest
00007 import rostest
00008 
00009 # Import other libraries
00010 from rospeex_if import ROSpeexInterface
00011 
00012 # import python libraries
00013 import os
00014 import sys
00015 import codecs
00016 
00017 
00018 class TestRospeexSS(unittest.TestCase):
00019     """ Speech Synthesis Test class """
00020     def __init__(self, *args, **kwargs):
00021         super(TestRospeexSS, self).__init__(*args, **kwargs)
00022         self._ready = 1
00023         self._wait_flag = True
00024 
00025     def _ss_response(self, data):
00026         """
00027         speech synthesis response callback
00028         @param message: message class
00029         @type  message: str
00030         """
00031         self._ready = 1
00032         rospy.loginfo("ReceiveResponse")
00033         self.assertNotEqual(data, None, 'Receive Response is None.')
00034 
00035     def read_input_data(self, target_file):
00036         """
00037         read input data
00038         @param target_file: target test data
00039         @type  target_file: str
00040         """
00041         data = ""
00042         try:
00043             print target_file
00044             f_log = codecs.open(target_file, 'r', 'utf_8')
00045             data = f_log.read()
00046             f_log.close()
00047         except:
00048             print 'no file'
00049         return data
00050 
00051     def execute_case(self, message, target_lang, target_engine, target_voice="", filename="hoge"):
00052         """
00053         execute test case
00054         @param message:
00055         @type  message:
00056         @param target_lang:
00057         @type  target_lang:
00058         @param target_engine:
00059         @type  target_engine:
00060         @param target_voice:
00061         @type  target_voice:
00062         """
00063         self._ready = 0
00064         # rospy.loginfo('Message: %s  VoiceFont: %s' % (message, target_voice))
00065         sound_filename = '%s.wav' % filename
00066         self._interface.tts(
00067             message,
00068             sound_filename,
00069             target_lang,
00070             target_engine,
00071             target_voice
00072         )
00073 
00074         while not self._ready and self._wait_flag:
00075             rospy.sleep(0.1)
00076 
00077     def test_run(self):
00078         """
00079         @param target_engine:
00080         @type  target_engine:
00081         @param target_dir:
00082         @type  target_dir:
00083         @param target_files_ja:
00084         @type  target_files_ja:
00085         @param  target_files_en:
00086         @type  target_files_en:
00087         """
00088         self._ready = 1
00089         rospy.init_node('test_rospeex_ss')
00090         self._interface = ROSpeexInterface()
00091         self._interface.init(ss=True, sr=False, spi=False)
00092         self._interface.register_ss_response(self._ss_response)
00093         rospy.sleep(0.5)
00094 
00095         target_dir = rospy.get_param('~target_dir', '../testdata')
00096         target_engine = rospy.get_param('~target_engine', 'nict')
00097         target_language = rospy.get_param('~target_language', 'ja')
00098         target_voicefonts = list(rospy.get_param('~target_voicefonts', ''))
00099         target_files = list(rospy.get_param('~target_files', ''))
00100         self._wait_flag = rospy.get_param('~wait_flag', True)
00101 
00102         if not rospy.is_shutdown():
00103             for target_file in target_files:
00104                 filename = os.path.join(target_dir, target_file)
00105                 message = self.read_input_data(filename)
00106                 for target_voicefont in target_voicefonts:
00107                     self.execute_case(
00108                         message,
00109                         target_language,
00110                         target_engine,
00111                         target_voicefont,
00112                         target_file
00113                     )
00114 
00115 
00116 if __name__ == '__main__':
00117     rostest.rosrun('rospeex_if', 'rospeex_ss_test', TestRospeexSS, sys.argv)


rospeex_if
Author(s): Komei Sugiura
autogenerated on Thu Jun 6 2019 18:53:13