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 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, data):
00031         """
00032         speech synthesis response callback
00033         @param message: message class
00034         @type  message: str
00035         """
00036         self._ready = 1
00037         rospy.loginfo("ReceiveResponse")
00038         self.assertNotEqual(data, None, 'Receive Response is None.')
00039 
00040     def read_input_data(self, target_file):
00041         """
00042         read input data
00043         @param target_file: target test data
00044         @type  target_file: str
00045         """
00046         data = ""
00047         try:
00048             print target_file
00049             f_log = codecs.open(target_file, 'r', 'utf_8')
00050             data = f_log.read()
00051             f_log.close()
00052         except:
00053             print 'no file'
00054         return data
00055 
00056 
00057     def execute_case(self, message, target_lang, target_engine, target_voice="", filename="hoge"):
00058         """
00059         execute test case
00060         @param message:
00061         @type  message:
00062         @param target_lang:
00063         @type  target_lang:
00064         @param target_engine:
00065         @type  target_engine:
00066         @param target_voice:
00067         @type  target_voice:
00068         """
00069         self._ready = 0
00070         # rospy.loginfo('Message: %s  VoiceFont: %s' % (message, target_voice))
00071         sound_filename = '%s.wav' % filename
00072         self._interface.tts(message, sound_filename, target_lang, target_engine, target_voice)
00073         while not self._ready and self._wait_flag:
00074             rospy.sleep(0.1)  # wait until callback response
00075 
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()
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(message, target_language, target_engine, target_voicefont, target_file)
00108 
00109 
00110 if __name__ == '__main__':
00111     rostest.rosrun('rospeex_if', 'rospeex_ss_test', TestRospeexSS, sys.argv)
00112 
00113 


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