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


rospeex_core
Author(s): Komei Sugiura
autogenerated on Wed Aug 26 2015 16:10:30