test_rospeex_ss_say.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, message):
00026         """
00027         speech synthesis response callback
00028         @param message: message class
00029         @type  message: str
00030         """
00031         self._ready = 1
00032         print 'received response'
00033 
00034     def read_input_data(self, target_file):
00035         """
00036         read input data
00037         @param target_file: target test data
00038         @type  target_file: str
00039         """
00040         data = ""
00041         try:
00042             print target_file
00043             f_log = codecs.open(target_file, 'r', 'utf_8')
00044             data = f_log.read()
00045             f_log.close()
00046         except:
00047             print 'no file'
00048         return data
00049 
00050     def execute_case(self, message, target_lang, target_engine, target_voice=""):
00051         """
00052         execute test case
00053         @param message:
00054         @type  message:
00055         @param target_lang:
00056         @type  target_lang:
00057         @param target_engine:
00058         @type  target_engine:
00059         @param target_voice:
00060         @type  target_voice:
00061         """
00062         self._ready = 0
00063         # rospy.loginfo('Message: %s  VoiceFont: %s' % (message, target_voice))
00064         self._interface.say(message, target_lang, target_engine, target_voice)
00065         while not self._ready and self._wait_flag:
00066             rospy.sleep(0.1)  # wait until callback response
00067 
00068     def test_run(self):
00069         """
00070         @param target_engine:
00071         @type  target_engine:
00072         @param target_dir:
00073         @type  target_dir:
00074         @param target_files_ja:
00075         @type  target_files_ja:
00076         @param  target_files_en:
00077         @type  target_files_en:
00078         """
00079         self._ready = 1
00080         rospy.init_node('test_rospeex_ss')
00081         self._interface = ROSpeexInterface()
00082         self._interface.init(ss=True, sr=False, spi=False)
00083         self._interface.register_ss_response(self._ss_response)
00084         rospy.sleep(0.5)
00085 
00086         target_dir = rospy.get_param('~target_dir', '../testdata')
00087         target_engine = rospy.get_param('~target_engine', 'nict')
00088         target_language = rospy.get_param('~target_language', 'ja')
00089         target_voicefonts = list(rospy.get_param('~target_voicefonts', ''))
00090         target_files = list(rospy.get_param('~target_files', ''))
00091         self._wait_flag = rospy.get_param('~wait_flag', True)
00092 
00093         if not rospy.is_shutdown():
00094             for target_file in target_files:
00095                 filename = os.path.join(target_dir, target_file)
00096                 message = self.read_input_data(filename)
00097                 for target_voicefont in target_voicefonts:
00098                     self.execute_case(
00099                         message,
00100                         target_language,
00101                         target_engine,
00102                         target_voicefont
00103                     )
00104 
00105 
00106 if __name__ == '__main__':
00107     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