Coverage Report - orca.acss

ModuleCoverage %
orca.acss
87%
1
# Orca
2
#
3
# Copyright 2005-2006 Google Inc.
4
# Portions Copyright 2007, Sun Microsystems, Inc.
5
#
6
# This library is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU Library General Public
8
# License as published by the Free Software Foundation; either
9
# version 2 of the License, or (at your option) any later version.
10
#
11
# This library is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# Library General Public License for more details.
15
#
16
# You should have received a copy of the GNU Library General Public
17
# License along with this library; if not, write to the
18
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
# Boston, MA 02111-1307, USA.
20
#
21
"""ACSS --- Aural CSS.
22
23
Class ACSS defines a simple wrapper for holding ACSS voice
24
definitions.  Speech engines implement the code for converting
25
ACSS definitions into engine-specific markup codes.
26
27 1
"""
28
29 1
__id__ = "$Id: acss.py 1973 2007-02-02 23:22:35Z wwalker $"
30 1
__author__ = "T. V. Raman"
31 1
__version__ = "$Revision: 1973 $"
32 1
__date__ = "$Date: 2007-02-02 15:22:35 -0800 (Fri, 02 Feb 2007) $"
33 1
__copyright__ = "Copyright (c) 2005 Google Inc."
34 1
__license__ = "LGPL"
35
36 2
class ACSS(dict):
37
38
    """Holds ACSS representation of a voice."""
39
40 1
    FAMILY        = 'family'
41 1
    RATE          = 'rate'
42 1
    GAIN          = 'gain'
43 1
    AVERAGE_PITCH = 'average-pitch'
44 1
    PITCH_RANGE   = 'pitch-range'
45 1
    STRESS        = 'stress'
46 1
    RICHNESS      = 'richness'
47 1
    PUNCTUATIONS  = 'punctuations'
48
49
    # A value of None means use the engine's default value.
50
    #
51 1
    settings = {
52
        FAMILY :        None,
53
        RATE :          50,
54
        GAIN :          5,
55
        AVERAGE_PITCH : 5,
56
        PITCH_RANGE :   5,
57
        STRESS :        5,
58
        RICHNESS :      5,
59
        PUNCTUATIONS :  'all'
60
    }
61
62 1
    def __init__(self,props={}):
63
        """Create and initialize ACSS structure."""
64 8
        for k in props:
65 2
            if k in ACSS.settings:
66
                # Do a 'deep copy' of the family.  Otherwise,
67
                # the new ACSS shares the actual data with the
68
                # props passed in.  This can cause unexpected
69
                # side effects.
70
                #
71 2
                if k == ACSS.FAMILY:
72 0
                    self[k] = {}
73 0
                    for j in props[k].keys():
74 0
                        self[k][j] = props[k][j]
75
                else:
76 2
                    self[k] = props[k]
77 6
        self.updateName()
78
79 1
    def __setitem__ (self, key, value):
80
        """Update name when we change values."""
81 2
        dict.__setitem__(self, key, value)
82 2
        self.updateName()
83
84 1
    def __delitem__(self, key):
85
        """Update name if we delete a key."""
86 0
        dict.__delitem__(self,key)
87 0
        self.updateName()
88
89 1
    def updateName(self):
90
        """Update name based on settings."""
91 8
        _name='acss-'
92 8
        names = self.keys()
93 8
        if names:
94 4
            names.sort()
95 8
            for  k in names:
96 4
                _name += "%s-%s:" % (k, self[k])
97 8
        self._name = _name[:-1]
98
99 1
    def name(self): return self._name