00001
00002
00003
00004
00005 import os
00006 import rospy
00007 import logging
00008 import unittest
00009 import ConfigParser
00010
00011
00012 from nose.tools import raises
00013 from nose.tools import nottest
00014
00015
00016 from rospeex_core.ss.voicetext import Client
00017 from rospeex_core import exceptions as ext
00018
00019
00020 FORMAT = '[%(levelname)s] %(message)s @%(filename)s:%(funcName)s:%(lineno)d'
00021 logging.basicConfig(format=FORMAT, level=logging.DEBUG)
00022 logger = logging.getLogger(__name__)
00023
00024
00025 class TestVoiceTextClient(unittest.TestCase):
00026 def setUp(self):
00027 rospy.init_node('rospeex_core')
00028
00029 base_dir = os.path.dirname(__file__)
00030 settings = ConfigParser.ConfigParser()
00031 filename = os.path.join(base_dir, 'config.cfg')
00032
00033 settings.read(filename)
00034
00035 self.big_text_file = os.path.join(
00036 base_dir,
00037 settings.get('SpeechSynthesis', 'big_text_for_voicetext_file')
00038 )
00039 self.api_key = settings.get('SpeechSynthesis', 'voicetext_api_key')
00040
00041 self.big_text_data = None
00042 with open(self.big_text_file, 'r') as f:
00043 self.big_text_data = f.read()
00044
00045 @raises(ext.ParameterException)
00046 def test_request_invalid_message(self):
00047 message = None
00048 language = 'ja'
00049 voice_font = '*'
00050 timeout = 100
00051 client = Client()
00052 client._key = self.api_key
00053 client.request(message, language, voice_font, timeout)
00054
00055 @raises(ext.ParameterException)
00056 def test_request_invalid_too_long_message(self):
00057 message = ''
00058 language = 'ja'
00059 voice_font = 'haruka'
00060 timeout = 100
00061 client = Client()
00062 client._key = self.api_key
00063
00064
00065 for i in range(300):
00066 message = message + 'a'
00067
00068 client.request(message, language, voice_font, timeout)
00069
00070 @raises(ext.ParameterException)
00071 def test_request_invalid_long_utf8_message(self):
00072 message = u''
00073 language = 'ja'
00074 voice_font = 'haruka'
00075 timeout = 100
00076 client = Client()
00077 client._key = self.api_key
00078
00079
00080 for i in range(201):
00081 message = message + u'あ'
00082 client.request(message, language, voice_font, timeout)
00083
00084 @nottest
00085 @raises(ext.InvalidResponseException)
00086 def test_request_invalid_message_charactor(self):
00087 message = '<'
00088 language = 'ja'
00089 voice_font = 'haruka'
00090 timeout = 100
00091 client = Client()
00092 client._key = self.api_key
00093 client.request(message, language, voice_font, timeout)
00094
00095 @raises(ext.UnsupportedLanguageException)
00096 def test_request_invalid_language(self):
00097 message = 'hello'
00098 language = 'de'
00099 voice_font = 'haruka'
00100 timeout = 100
00101 client = Client()
00102 client._key = self.api_key
00103 client.request(message, language, voice_font, timeout)
00104
00105 @raises(ext.ParameterException)
00106 def test_request_invalid_api_key(self):
00107 message = 'hello'
00108 language = 'ja'
00109 voice_font = 'haruka'
00110 timeout = 100
00111 client = Client()
00112 client.request(message, language, voice_font, timeout)
00113
00114 @raises(ext.InvalidResponseException)
00115 def test_request_invalid_url(self):
00116 message = 'hello'
00117 language = 'ja'
00118 voice_font = 'haruka'
00119 timeout = 100
00120 client = Client()
00121 client.URL = 'http://rospeex.nict.go.jp/nauth_json/jsServices/hoge'
00122 client._key = self.api_key
00123 client.request(message, language, voice_font, timeout)
00124
00125 @raises(ext.ParameterException)
00126 def test_request_invalid_voice_font(self):
00127 message = 'hello'
00128 language = 'ja'
00129 voice_font = 'hogehoge'
00130 timeout = 100
00131 client = Client()
00132 client._key = self.api_key
00133 client.request(message, language, voice_font, timeout)
00134
00135 @raises(ext.ParameterException)
00136 def test_request_invalid_pitch_high(self):
00137 message = 'hello'
00138 language = 'ja'
00139 voice_font = 'show'
00140 timeout = 100
00141 client = Client()
00142 client._key = self.api_key
00143 client._pitch = 201
00144 client.request(message, language, voice_font, timeout)
00145
00146 @raises(ext.ParameterException)
00147 def test_request_invalid_pitch_low(self):
00148 message = 'hello'
00149 language = 'ja'
00150 voice_font = 'show'
00151 timeout = 100
00152 client = Client()
00153 client._key = self.api_key
00154 client._pitch = 49
00155 client.request(message, language, voice_font, timeout)
00156
00157 @raises(ext.ParameterException)
00158 def test_request_invalid_volume_high(self):
00159 message = 'hello'
00160 language = 'ja'
00161 voice_font = 'show'
00162 timeout = 100
00163 client = Client()
00164 client._key = self.api_key
00165 client._volume = 201
00166 client.request(message, language, voice_font, timeout)
00167
00168 @raises(ext.ParameterException)
00169 def test_request_invalid_volume_low(self):
00170 message = 'hello'
00171 language = 'ja'
00172 voice_font = 'show'
00173 timeout = 100
00174 client = Client()
00175 client._key = self.api_key
00176 client._volume = 49
00177 client.request(message, language, voice_font, timeout)
00178
00179 @raises(ext.ParameterException)
00180 def test_request_invalid_speed_high(self):
00181 message = 'hello'
00182 language = 'ja'
00183 voice_font = 'show'
00184 timeout = 100
00185 client = Client()
00186 client._key = self.api_key
00187 client._speed = 401
00188 client.request(message, language, voice_font, timeout)
00189
00190 @raises(ext.ParameterException)
00191 def test_request_invalid_speed_low(self):
00192 message = 'hello'
00193 language = 'ja'
00194 voice_font = 'show'
00195 timeout = 100
00196 client = Client()
00197 client._key = self.api_key
00198 client._speed = 49
00199 client.request(message, language, voice_font, timeout)
00200
00201 @raises(ext.ParameterException)
00202 def test_request_invalid_emotional_user(self):
00203 message = 'hello'
00204 language = 'ja'
00205 voice_font = 'show'
00206 timeout = 100
00207 client = Client()
00208 client._key = self.api_key
00209 client._emotion = 'anger'
00210 client.request(message, language, voice_font, timeout)
00211
00212 @raises(ext.ParameterException)
00213 def test_request_invalid_emotion_type(self):
00214 message = 'hello'
00215 language = 'ja'
00216 voice_font = 'bear'
00217 timeout = 100
00218 client = Client()
00219 client._key = self.api_key
00220 client._emotion = 'hoge'
00221 client.request(message, language, voice_font, timeout)
00222
00223 @nottest
00224 @raises(ext.RequestTimeoutException)
00225 def test_request_server_timeout_post(self):
00226 message = self.big_text_data
00227 language = 'ja'
00228 voice_font = 'haruka'
00229 timeout = 2
00230 client = Client()
00231 client._key = self.api_key
00232 client.request(message, language, voice_font, timeout)
00233
00234 def test_request_valid_big_message(self):
00235 message = self.big_text_data
00236 language = 'ja'
00237 voice_font = 'haruka'
00238 timeout = 1000000
00239 client = Client()
00240 client._key = self.api_key
00241 client.request(message, language, voice_font, timeout)
00242
00243 def test_request_valid_japanese_message(self):
00244 message = u'こんにちは'
00245 language = 'ja'
00246 voice_font = 'haruka'
00247 timeout = 10000
00248 client = Client()
00249 client._key = self.api_key
00250 client.request(message, language, voice_font, timeout)
00251
00252 def test_request_valid_voice_fonts(self):
00253 message = u'こんにちは'
00254 language = 'ja'
00255 timeout = 10000
00256 client = Client()
00257 client._key = self.api_key
00258
00259 for speaker in client.SPEAKER_LIST:
00260 client.request(message, language, speaker, timeout)
00261
00262
00263 if __name__ == '__main__':
00264 import rosunit
00265 test_class = TestVoiceTextClient
00266 rosunit.unitrun(
00267 'rospeex_core',
00268 'speech_synthesis_client_voicetext',
00269 test_class,
00270 None,
00271 coverage_packages=['rospeex_core.ss']
00272 )