3
# Copyright (C) 2003, 2006, 2007 Brailcom, o.p.s.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public Licensex1 as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
from .client import PunctuationMode, CallbackType, SSIPClient, Scope, Speaker
25
class _SSIPClientTest(unittest.TestCase):
28
self._client = SSIPClient('test')
29
self._client.set_language('en')
30
self._client.set_rate(30)
35
class AutomaticTest(_SSIPClientTest):
36
"""A set of tests which may be evaluated automatically.
38
Please put all tests which require a user to listen to their output to the
42
def test_callbacks(self):
43
# TODO: This needs to be fixed. There is no guarantee that
44
# the message will start in one second nor is there any
45
# guarantee that it will start at all. It can be interrupted
46
# by other applications etc. Also there is no guarantee that
47
# the cancel will arrive on time and the end callback will be
48
# received on time. Also the combination cancel/end does not have
49
# to work as expected and SD and the interface can still be ok.
51
self._client.set_output_module('flite')
52
called = {CallbackType.BEGIN: [],
53
CallbackType.CANCEL: [],
55
self._client.speak("This message should get interrupted. It is "
56
"hopefully long enough to last more than 1 second.",
57
callback=lambda type: called[type].append('msg1'))
58
self._client.speak("This second message should not be spoken at all.",
59
callback=lambda type: called[type].append('msg2'))
62
self._client.speak("Hi.",
63
callback=lambda type: called[type].append('msg3'))
64
# Wait for pending events...
66
started, canceled, ended = [called[t] for t in (CallbackType.BEGIN,
69
assert started == ['msg1', 'msg3'] and ended == ['msg3'] and \
70
'msg1' in canceled and 'msg2' in canceled and \
71
'msg3' not in canceled, \
73
"This failure only indicates a possible error. The test "
74
"depends on proper timing and results may warry depending "
75
"on the used output module and other conditions. See the "
76
"code of this test method if you want to investigate "
81
class VoiceTest(_SSIPClientTest):
82
"""This set of tests requires a user to listen to it.
84
The success or failure of the tests defined here can not be detected
89
def test_escapes(self):
91
c.speak("Testing data escapes:")
92
c.set_punctuation(PunctuationMode.ALL)
94
c.speak("Marker at the end.\r\n.\r\n")
95
c.speak(".\r\nMarker at the beginning.")
97
def test_voice_properties(self):
99
c.speak("Testing voice properties:")
101
c.speak("I am fat Billy")
103
c.speak("I am slim Willy")
106
c.speak("I am quick Dick.")
108
c.speak("I am slow Joe.")
112
c.speak("I am quiet Mariette.")
114
c.speak("I am noisy Daisy.")
116
def test_other_commands(self):
118
c.speak("Testing other commands:")
121
c.sound_icon("empty")
123
def test_lists(self):
125
for module in c.list_output_modules():
126
c.set_output_module(module)
128
c.speak(module +"using default voice")
129
for name, lang, dialect in c.list_synthesis_voices():
130
print(" -", module, name, lang, dialect)
131
c.set_synthesis_voice(name)
132
c.speak(module +" using voice "+ name)
135
if __name__ == '__main__':