16 from __future__
import print_function
25 from tts.srv
import Polly
26 from tts.srv
import PollyResponse
27 from tts.srv
import Synthesizer
28 from tts.srv
import SynthesizerResponse
52 rospy.wait_for_service(
'polly')
53 polly = rospy.ServiceProxy(
'polly', Polly)
55 test_text =
'Mary has a little lamb, little lamb, little lamb.' 56 res = polly(polly_action=
'SynthesizeSpeech', text=test_text)
57 self.assertIsNotNone(res)
58 self.assertTrue(type(res)
is PollyResponse)
60 r = json.loads(res.result)
61 self.assertIn(
'Audio Type', r,
'result should contain audio type')
62 self.assertIn(
'Audio File', r,
'result should contain file path')
63 self.assertIn(
'Amazon Polly Response Metadata', r,
'result should contain metadata')
65 audio_type = r[
'Audio Type']
66 audio_file = r[
'Audio File']
67 md = r[
'Amazon Polly Response Metadata']
68 self.assertTrue(
"'HTTPStatusCode': 200," in md)
69 self.assertEqual(
'audio/ogg', audio_type)
70 self.assertTrue(audio_file.endswith(
'.ogg'))
73 o = subprocess.check_output([
'file', audio_file], stderr=subprocess.STDOUT)
75 m = re.search(
r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
76 self.assertIsNotNone(m)
81 test_text =
'Mary has a little lamb, little lamb, little lamb.' 82 res = polly.synthesize(text=test_text)
83 self.assertIsNotNone(res)
84 self.assertTrue(type(res)
is PollyResponse)
86 r = json.loads(res.result)
87 self.assertIn(
'Audio Type', r,
'result should contain audio type')
88 self.assertIn(
'Audio File', r,
'result should contain file path')
89 self.assertIn(
'Amazon Polly Response Metadata', r,
'result should contain metadata')
91 audio_type = r[
'Audio Type']
92 audio_file = r[
'Audio File']
93 md = r[
'Amazon Polly Response Metadata']
94 self.assertTrue(
"'HTTPStatusCode': 200," in md)
95 self.assertEqual(
'audio/ogg', audio_type)
96 self.assertTrue(audio_file.endswith(
'.ogg'))
99 o = subprocess.check_output([
'file', audio_file], stderr=subprocess.STDOUT)
101 m = re.search(
r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
102 self.assertIsNotNone(m)
105 rospy.wait_for_service(
'synthesizer')
106 speech_synthesizer = rospy.ServiceProxy(
'synthesizer', Synthesizer)
108 text =
'Mary has a little lamb, little lamb, little lamb.' 109 res = speech_synthesizer(text=text)
110 self.assertIsNotNone(res)
111 self.assertTrue(type(res)
is SynthesizerResponse)
113 r = json.loads(res.result)
114 self.assertIn(
'Audio Type', r,
'result should contain audio type')
115 self.assertIn(
'Audio File', r,
'result should contain file path')
116 self.assertIn(
'Amazon Polly Response Metadata', r,
'result should contain metadata')
118 audio_type = r[
'Audio Type']
119 audio_file = r[
'Audio File']
120 md = r[
'Amazon Polly Response Metadata']
121 self.assertTrue(
"'HTTPStatusCode': 200," in md)
122 self.assertEqual(
'audio/ogg', audio_type)
123 self.assertTrue(audio_file.endswith(
'.ogg'))
126 o = subprocess.check_output([
'file', audio_file], stderr=subprocess.STDOUT)
128 m = re.search(
r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
129 self.assertIsNotNone(m)
132 rospy.wait_for_service(
'polly')
133 polly = rospy.ServiceProxy(
'polly', Polly)
135 test_text =
'Mary has a little lamb, little lamb, little lamb.' 136 res = polly(polly_action=
'SynthesizeSpeech', text=test_text, output_format=
'mp3')
137 self.assertIsNotNone(res)
138 self.assertTrue(type(res)
is PollyResponse)
140 r = json.loads(res.result)
141 self.assertIn(
'Audio Type', r,
'result should contain audio type')
142 self.assertIn(
'Audio File', r,
'result should contain file path')
143 self.assertIn(
'Amazon Polly Response Metadata', r,
'result should contain metadata')
145 audio_type = r[
'Audio Type']
146 audio_file = r[
'Audio File']
147 md = r[
'Amazon Polly Response Metadata']
148 self.assertTrue(
"'HTTPStatusCode': 200," in md)
149 self.assertEqual(
'audio/mpeg', audio_type)
150 self.assertTrue(audio_file.endswith(
'.mp3'))
153 o = subprocess.check_output([
'file', audio_file], stderr=subprocess.STDOUT)
155 m = re.search(
r'.*MPEG.*layer III.*', o, flags=re.MULTILINE)
156 self.assertIsNotNone(m)
159 rospy.wait_for_service(
'polly')
160 polly = rospy.ServiceProxy(
'polly', Polly)
162 text =
'<speak>Mary has a little lamb, little lamb, little lamb.</speak>' 163 res = polly(polly_action=
'SynthesizeSpeech', text=text, text_type=
'ssml')
164 self.assertIsNotNone(res)
165 self.assertTrue(type(res)
is PollyResponse)
167 r = json.loads(res.result)
168 self.assertIn(
'Audio Type', r,
'result should contain audio type')
169 self.assertIn(
'Audio File', r,
'result should contain file path')
170 self.assertIn(
'Amazon Polly Response Metadata', r,
'result should contain metadata')
172 audio_type = r[
'Audio Type']
173 audio_file = r[
'Audio File']
174 md = r[
'Amazon Polly Response Metadata']
175 self.assertTrue(
"'HTTPStatusCode': 200," in md)
176 self.assertEqual(
'audio/ogg', audio_type)
177 self.assertTrue(audio_file.endswith(
'.ogg'))
180 o = subprocess.check_output([
'file', audio_file], stderr=subprocess.STDOUT)
182 m = re.search(
r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
183 self.assertIsNotNone(m)
186 rospy.wait_for_service(
'synthesizer')
187 speech_synthesizer = rospy.ServiceProxy(
'synthesizer', Synthesizer)
189 text =
'<speak>Mary has a little lamb, little lamb, little lamb.</speak>' 190 res = speech_synthesizer(text=text, metadata=
'''{"text_type":"ssml"}''')
191 self.assertIsNotNone(res)
192 self.assertTrue(type(res)
is SynthesizerResponse)
194 r = json.loads(res.result)
195 self.assertIn(
'Audio Type', r,
'result should contain audio type')
196 self.assertIn(
'Audio File', r,
'result should contain file path')
197 self.assertIn(
'Amazon Polly Response Metadata', r,
'result should contain metadata')
199 audio_type = r[
'Audio Type']
200 audio_file = r[
'Audio File']
201 md = r[
'Amazon Polly Response Metadata']
202 self.assertTrue(
"'HTTPStatusCode': 200," in md)
203 self.assertEqual(
'audio/ogg', audio_type)
204 self.assertTrue(audio_file.endswith(
'.ogg'))
207 o = subprocess.check_output([
'file', audio_file], stderr=subprocess.STDOUT)
209 m = re.search(
r'.*Ogg data, Vorbis audi.*', o, flags=re.MULTILINE)
210 self.assertIsNotNone(m)
213 if __name__ ==
'__main__':
214 rostest.rosrun(PKG, NAME, TestPlainText, sys.argv)
def test_plain_text_via_synthesizer_node(self)
def test_simple_ssml_via_polly_node(self)
def test_simple_ssml_via_synthesizer_node(self)
def test_plain_text_using_polly_class(self)
def test_plain_text_to_wav_via_polly_node(self)
def test_plain_text_to_mp3_via_polly_node(self)