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 try:
00006     import roslib; roslib.load_manifest('rospeex')
00007 except:
00008     pass
00009 
00010 import rospy
00011 import unittest
00012 import rostest
00013 
00014 # Import other libraries
00015 from rospeex_if import ROSpeexInterface
00016 
00017 # import python libraries
00018 import os
00019 import sys
00020 import codecs
00021 
00022 
00023 class TestRospeexSS(unittest.TestCase):
00024     """ Speech Synthesis Test class """
00025     def __init__(self, *args, **kwargs):
00026         super(TestRospeexSS, self).__init__(*args, **kwargs)
00027         self._ready = 1
00028         self._wait_flag = True
00029 
00030     def _ss_response(self, message):
00031         """
00032         speech synthesis response callback
00033         @param message: message class
00034         @type  message: str
00035         """
00036         self._ready = 1
00037         print 'received response'
00038 
00039     def read_input_data(self, target_file):
00040         """
00041         read input data
00042         @param target_file: target test data
00043         @type  target_file: str
00044         """
00045         data = ""
00046         try:
00047             print target_file
00048             f_log = codecs.open(target_file, 'r', 'utf_8')
00049             data = f_log.read()
00050             f_log.close()
00051         except:
00052             print 'no file'
00053         return data
00054 
00055 
00056     def execute_case(self, message, target_lang, target_engine, target_voice=""):
00057         """
00058         execute test case
00059         @param message:
00060         @type  message:
00061         @param target_lang:
00062         @type  target_lang:
00063         @param target_engine:
00064         @type  target_engine:
00065         @param target_voice:
00066         @type  target_voice:
00067         """
00068         self._ready = 0
00069         # rospy.loginfo('Message: %s  VoiceFont: %s' % (message, target_voice))
00070         self._interface.say(message, target_lang, target_engine, target_voice)
00071         while not self._ready and self._wait_flag:
00072             rospy.sleep(0.1)  # wait until callback response
00073 
00074 
00075     def test_run(self):
00076         """
00077         @param target_engine:
00078         @type  target_engine:
00079         @param target_dir:
00080         @type  target_dir:
00081         @param target_files_ja:
00082         @type  target_files_ja:
00083         @param  target_files_en:
00084         @type  target_files_en:
00085         """
00086         self._ready = 1
00087         rospy.init_node('test_rospeex_ss')
00088         self._interface = ROSpeexInterface()
00089         self._interface.init()
00090         self._interface.register_ss_response(self._ss_response)
00091         rospy.sleep(0.5)
00092 
00093         target_dir      = rospy.get_param('~target_dir', '../testdata')
00094         target_engine   = rospy.get_param('~target_engine', 'nict')
00095         target_language = rospy.get_param('~target_language', 'ja')
00096         target_voicefonts = list(rospy.get_param('~target_voicefonts', ''))
00097         target_files      = list(rospy.get_param('~target_files', ''))
00098         self._wait_flag = rospy.get_param('~wait_flag', True)
00099 
00100         if not rospy.is_shutdown():
00101             for target_file in target_files:
00102                 filename = os.path.join( target_dir, target_file )
00103                 message = self.read_input_data(filename)
00104                 for target_voicefont in target_voicefonts:
00105                     self.execute_case(message, target_language, target_engine, target_voicefont)
00106 
00107 
00108 if __name__ == '__main__':
00109     rostest.rosrun('rospeex_if', 'rospeex_ss_test', TestRospeexSS, sys.argv)
00110 
00111 


rospeex_if
Author(s): Komei Sugiura
autogenerated on Wed Aug 26 2015 16:10:32