Go to the documentation of this file.00001
00002
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 logging
00013 import unittest
00014 from nose.tools import eq_, raises
00015 import ConfigParser
00016
00017 from rospeex_core.ss.client_google import SpeechSynthesisClient_Google
00018 from rospeex_core.exceptions import ParameterException
00019 from rospeex_core.exceptions import InvalidResponseException
00020 from rospeex_core.exceptions import InvalidRequestException
00021 from rospeex_core.exceptions import RequestTimeoutException
00022 from rospeex_core.exceptions import SpeechSynthesisException
00023 from rospeex_core.exceptions import UnsupportedLanguageException
00024
00025
00026 logger = logging.getLogger(__name__)
00027 logger.setLevel(logging.DEBUG)
00028 formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(filename)s:%(lineno)d:%(message)s')
00029 ch = logging.StreamHandler()
00030 ch.setFormatter(formatter)
00031 logger.addHandler(ch)
00032
00033
00034 class TestSpeechSynthesisClient_Google(unittest.TestCase):
00035 def setUp(self):
00036 base_dir = os.path.dirname(__file__)
00037 settings = ConfigParser.ConfigParser()
00038 filename = os.path.join(base_dir, 'config.cfg')
00039 settings.read(filename)
00040 self.big_text_file = os.path.join(base_dir, settings.get('SpeechSynthesis', 'big_text_for_google_file'))
00041
00042 self.big_text_data = None
00043 with open(self.big_text_file, 'r') as f:
00044 self.big_text_data = f.read()
00045
00046
00047 @raises(ParameterException)
00048 def test_request_invalid_message(self):
00049 message = None
00050 language = 'ja'
00051 voice_font = '*'
00052 timeout = 100
00053 client = SpeechSynthesisClient_Google()
00054 client.request(message, language, voice_font, timeout)
00055
00056
00057 @raises(UnsupportedLanguageException)
00058 def test_request_invalid_language(self):
00059 message = 'hello'
00060 language = 'de'
00061 voice_font = '*'
00062 timeout = 100
00063 client = SpeechSynthesisClient_Google()
00064 client.request(message, language, voice_font, timeout)
00065
00066
00067 @raises(InvalidRequestException)
00068 def test_request_invalid_url(self):
00069 message = 'hello'
00070 language = 'en'
00071 voice_font = '*'
00072 timeout = 100
00073 client = SpeechSynthesisClient_Google()
00074 client.URL = 'http://translate.google.com/translate_tts2?'
00075 client.request(message, language, voice_font, timeout)
00076
00077
00078 """
00079 @raises(SpeechSynthesisException)
00080 def test_request_invalid_voice_font(self):
00081 message = 'hello'
00082 language = 'ja'
00083 voice_font = 'hogehoge'
00084 timeout = 100
00085 client = SpeechSynthesisClient_Google()
00086 client.request(message, language, voice_font, timeout)
00087
00088
00089 @raises(RequestTimeoutException)
00090 def test_request_server_timeout_prev(self):
00091 message = self.big_text_data
00092 language = 'en'
00093 voice_font = '*'
00094 timeout = 1
00095 client = SpeechSynthesisClient_Google()
00096 client.request(message, language, voice_font, timeout)
00097
00098
00099 @raises(RequestTimeoutException)
00100 def test_request_server_timeout_post(self):
00101 message = self.big_text_data
00102 language = 'en'
00103 voice_font = '*'
00104 timeout = 2
00105 client = SpeechSynthesisClient_Google()
00106 client.request(message, language, voice_font, timeout)
00107 """
00108
00109
00110 def test_request_valid_big_message(self):
00111 message = self.big_text_data
00112 language = 'en'
00113 voice_font = '*'
00114 timeout = 100
00115 client = SpeechSynthesisClient_Google()
00116 client.request(message, language, voice_font, timeout)
00117
00118
00119 def test_request_valid_japanese_message(self):
00120 message = u'こんにちは'
00121 language = 'ja'
00122 voice_font = '*'
00123 timeout = 100
00124 client = SpeechSynthesisClient_Google()
00125 client.request(message, language, voice_font, timeout)
00126
00127
00128 def test_request_valid_english_message(self):
00129 message = 'hello everyone.'
00130 language = 'en'
00131 voice_font = '*'
00132 timeout = 100
00133 client = SpeechSynthesisClient_Google()
00134 client.request(message, language, voice_font, timeout)
00135
00136
00137 if __name__ == '__main__':
00138 import rosunit
00139 test_class = TestSpeechSynthesisClient_Google
00140 rosunit.unitrun(PKG_NAME, 'speech_synthesis_client_google', test_class, None, coverage_packages=['rospeex.ss'])