Python LMF library
 All Classes Namespaces Files Functions Variables
audio.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """! @package resources
4 """
5 
6 from material import Material
7 from common.range import mediaType_range, quality_range
8 from utils.attr import check_attr_type, check_attr_range, check_time_format, check_duration_format
9 from utils.io import ENCODING
10 
11 class Audio(Material):
12  """! Audio is a Material subclass representing an audio recording.
13  """
14  def __init__(self):
15  """! @brief Constructor.
16  Audio instances are owned by FormRepresentation.
17  @return An Audio instance.
18  """
19  # Initialize Material attributes: 'mediaType', 'fileName' and 'author'
20  self.__new__()
21  self.quality = None
22  self.sound = None
23  self.startPosition = None
25  self.externalReference = None
26  self.audioFileFormat = None
27  self.transcription = None
28 
29  def __del__(self):
30  """! @brief Destructor.
31  """
32  pass
33 
34  def set_mediaType(self, media_type):
35  """! @brief Set media type.
36  @param media_type Type to set.
37  @return Audio instance.
38  """
39  error_msg = "Media type value '%s' is not allowed" % media_type.encode(ENCODING)
40  check_attr_type(media_type, [str, unicode], error_msg)
41  self.mediaType = check_attr_range(str(media_type), mediaType_range, error_msg)
42  return self
43 
44  def get_mediaType(self):
45  """! @brief Get media type.
46  @return Audio attribute 'mediaType'.
47  """
48  return self.mediaType
49 
50  def set_fileName(self, file_name):
51  """! @brief Set file name.
52  @param file_name Name to set.
53  @return Audio instance.
54  """
55  error_msg = "File name value '%s' is not allowed" % file_name.encode(ENCODING)
56  check_attr_type(file_name, [str, unicode], error_msg)
57  self.fileName = file_name
58  return self
59 
60  def get_fileName(self):
61  """! @brief Get file name.
62  @return Audio attribute 'fileName'.
63  """
64  return self.fileName
65 
66  def set_author(self, author):
67  """! @brief Set author of the material resource.
68  @param author Author to set.
69  @return Audio instance.
70  """
71  error_msg = "Author value '%s' is not allowed" % author.encode(ENCODING)
72  check_attr_type(author, [str, unicode], error_msg)
73  self.author = author
74  return self
75 
76  def get_author(self):
77  """! @brief Get author of the material resource.
78  @return Audio attribute 'author'.
79  """
80  return self.author
81 
82  def set_quality(self, quality):
83  """! @brief Set audio recording quality.
84  @param quality Quality to set.
85  @return Audio instance.
86  """
87  error_msg = "Quality value '%s' is not allowed" % quality.encode(ENCODING)
88  check_attr_type(quality, [str, unicode], error_msg)
89  self.quality = check_attr_range(str(quality), quality_range, error_msg)
90  return self
91 
92  def get_quality(self):
93  """! @brief Get audio recording quality.
94  @return Audio attribute 'quality'.
95  """
96  return self.quality
97 
98  def set_sound(self, sound):
99  """! @brief Set sound.
100  @param sound Sound to set.
101  @return Audio instance.
102  """
103  error_msg = "Sound value '%s' is not allowed" % sound.encode(ENCODING)
104  check_attr_type(sound, [str, unicode], error_msg)
105  self.sound = sound
106  return self
107 
108  def get_sound(self):
109  """! @brief Get sound.
110  @return Audio attribute 'sound'.
111  """
112  return self.sound
113 
114  def set_transcription(self, transcription):
115  """! @brief Set transcription of the audio recording.
116  @param Transcription to set.
117  @return Audio instance.
118  """
119  error_msg = "Transcription value '%s' is not allowed" % transcription.encode(ENCODING)
120  check_attr_type(transcription, [str, unicode], error_msg)
121  self.transcription = transcription
122  return self
123 
124  def get_transcription(self):
125  """! @brief Get transcription of the audio recording.
126  @return Audio attribute 'transcription'.
127  """
128  return self.transcription
129 
130  def set_startPosition(self, start_position):
131  """! @brief Set start position.
132  @param start_position Start position to set.
133  @return Audio instance.
134  """
135  error_msg = "Start position value '%s' is not allowed" % start_position.encode(ENCODING)
136  check_attr_type(start_position, [str, unicode], error_msg)
137  if start_position[0] != 'T':
138  # Add 'T' for Time
139  start_position = 'T' + start_position
140  check_time_format(start_position)
141  self.startPosition = start_position
142  return self
143 
144  def get_startPosition(self):
145  """! @brief Get start position.
146  @return Audio attribute 'startPosition'.
147  """
148  return self.startPosition
149 
150  def set_durationOfEffectiveSpeech(self, duration):
151  """! @brief Set duration of effective speech.
152  @param duration Duration of effective speech to set.
153  @return Audio instance.
154  """
155  error_msg = "Duration of effective speech value '%s' is not allowed" % duration.encode(ENCODING)
156  check_attr_type(duration, [str, unicode], error_msg)
157  if duration[0] != 'P':
158  if duration[0] != 'T':
159  # Add 'T' for Time
160  duration = 'T' + duration
161  # Add 'P' for Period
162  duration = 'P' + duration
163  check_duration_format(duration)
164  self.durationOfEffectiveSpeech = duration
165  return self
166 
168  """! @brief Get duration of effective speech.
169  @return Audio attribute 'durationOfEffectiveSpeech'.
170  """
171  return self.durationOfEffectiveSpeech
172 
173  def set_externalReference(self, external_reference):
174  """! @brief Set external reference.
175  @param external_reference External reference to set.
176  @return Audio instance.
177  """
178  error_msg = "External reference value '%s' is not allowed" % external_reference.encode(ENCODING)
179  check_attr_type(external_reference, [str, unicode], error_msg)
180  self.externalReference = external_reference
181  return self
182 
184  """! @brief Get external reference.
185  @return Audio attribute 'externalReference'.
186  """
187  return self.externalReference
188 
189  def set_audioFileFormat(self, audio_file_format):
190  """! @brief Set audio file format.
191  @param audio_file_format Audio file format to set.
192  @return Audio instance.
193  """
194  error_msg = "Audio file format value '%s' is not allowed" % audio_file_format.encode(ENCODING)
195  check_attr_type(audio_file_format, [str, unicode], error_msg)
196  self.audioFileFormat = audio_file_format
197  return self
198 
200  """! @brief Get audio file formay.
201  @return Audio attribute 'audioFileFormat'.
202  """
203  return self.audioFileFormat
def get_externalReference
Get external reference.
Definition: audio.py:183
def check_attr_type
Check that attribute value is of specified type.
Definition: attr.py:9
def get_mediaType
Get media type.
Definition: audio.py:44
def set_externalReference
Set external reference.
Definition: audio.py:173
def get_durationOfEffectiveSpeech
Get duration of effective speech.
Definition: audio.py:167
def set_mediaType
Set media type.
Definition: audio.py:34
def check_attr_range
Check that attribute value is in specified range.
Definition: attr.py:23
def set_fileName
Set file name.
Definition: audio.py:50
def check_time_format
Verify that time format is composed as follows: THH:MM:SS,MSMS (ISO 8601: 'T' for Time)...
Definition: attr.py:57
def set_transcription
Set transcription of the audio recording.
Definition: audio.py:114
def get_author
Get author of the material resource.
Definition: audio.py:76
def set_audioFileFormat
Set audio file format.
Definition: audio.py:189
def get_fileName
Get file name.
Definition: audio.py:60
def get_quality
Get audio recording quality.
Definition: audio.py:92
def check_duration_format
Verify that duration format is composed as follows: PTxxHxxMxxS (ISO 8601: 'P' for Period)...
Definition: attr.py:66
def get_startPosition
Get start position.
Definition: audio.py:144
def get_transcription
Get transcription of the audio recording.
Definition: audio.py:124
def set_durationOfEffectiveSpeech
Set duration of effective speech.
Definition: audio.py:150
def set_author
Set author of the material resource.
Definition: audio.py:66
def get_audioFileFormat
Get audio file formay.
Definition: audio.py:199
def set_quality
Set audio recording quality.
Definition: audio.py:82
Audio is a Material subclass representing an audio recording.
Definition: audio.py:11
def set_startPosition
Set start position.
Definition: audio.py:130