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