88"""
99
1010
11+ try :
12+ import StringIO as SIO
13+ except ImportError :
14+ import io as SIO
15+ import base64
16+ import json
1117from pprint import pformat
18+
19+ from pymediainfo import MediaInfo
1220from six import iteritems
1321
22+
1423class DiarizeAudio (object ):
1524
16- def __init__ (self , encoding = None , sample_rate = None , language_code = 'en-US' , content = None , speakers = - 1 ):
25+ def __init__ (self , encoding = None , sample_rate = None , language_code = 'en-US' , content = None , speakers = - 1 ,
26+ merge_segments = True , audio_type = "default" ):
1727 """
1828 DiarizeAudio - a model defined in Swagger
1929
@@ -27,22 +37,28 @@ def __init__(self, encoding=None, sample_rate=None, language_code='en-US', conte
2737 'sample_rate' : 'int' ,
2838 'language_code' : 'str' ,
2939 'content' : 'str' ,
30- 'speakers' : 'int'
40+ 'speakers' : 'int' ,
41+ 'audio_type' : 'str' ,
42+ 'merge_segments' : 'bool'
3143 }
3244
3345 self .attribute_map = {
3446 'encoding' : 'encoding' ,
3547 'sample_rate' : 'sampleRate' ,
3648 'language_code' : 'languageCode' ,
3749 'content' : 'content' ,
38- 'speakers' : 'speakers'
50+ 'speakers' : 'speakers' ,
51+ 'audio_type' : 'audioType' ,
52+ 'merge_segments' : 'vad'
3953 }
4054
4155 self ._encoding = encoding
4256 self ._sample_rate = sample_rate
4357 self ._language_code = language_code
4458 self ._content = content
4559 self ._speakers = speakers
60+ self ._merge_segments = merge_segments
61+ self ._audio_type = audio_type
4662
4763 @property
4864 def encoding (self ):
@@ -169,6 +185,55 @@ def speakers(self, speakers):
169185
170186 self ._speakers = speakers
171187
188+ @property
189+ def audio_type (self ):
190+ """
191+ Gets the corresponding type of audio file
192+ example: meeting, call-center, default
193+
194+ :return: The audio_type of this DiarizeAudio.
195+ :rtype: str
196+ """
197+ return self ._audio_type
198+
199+ @audio_type .setter
200+ def audio_type (self , audio_type ):
201+ """
202+ Sets the audio_type of this DiarizeAudio.
203+ Corresponding type of audio file like meeting, call-center, default
204+
205+ :param encoding: The audio_type of this DiarizeAudio.
206+ :type: str
207+ """
208+ if audio_type is None :
209+ raise ValueError ("Invalid value for `audio_type`, must not be `None`" )
210+
211+ self ._audio_type = audio_type
212+
213+ @property
214+ def merge_segments (self ):
215+ """
216+ Whether the consecutive segments of same speaker should be merged
217+
218+ :return: The merge_segments of this DiarizeAudio.
219+ :rtype: bool
220+ """
221+ return self ._merge_segments
222+
223+ @merge_segments .setter
224+ def merge_segments (self , merge_segments ):
225+ """
226+ Sets the merge_segments of this DiarizeAudio.
227+ Whether the consecutive segments of same speaker should be merged
228+
229+ :param encoding: The merge_segments of this DiarizeAudio.
230+ :type: str
231+ """
232+ if merge_segments is None :
233+ raise ValueError ("Invalid value for `merge_segments`, must not be `None`" )
234+
235+ self ._merge_segments = merge_segments
236+
172237 def to_dict (self ):
173238 """
174239 Returns the model properties as a dict
@@ -221,3 +286,26 @@ def __ne__(self, other):
221286 Returns true if both objects are not equal
222287 """
223288 return not self == other
289+
290+ @staticmethod
291+ def from_file (file_name , language_code = 'en-US' , speakers = - 1 , merge_segments = True , audio_type = 'default' ):
292+ media_info = MediaInfo .parse (file_name )
293+ codec = media_info .tracks [0 ].__dict__ ['codec' ]
294+ sampling_rate = media_info .tracks [1 ].__dict__ ['sampling_rate' ]
295+ fout = SIO .StringIO ()
296+ with open (file_name , 'rb' ) as fin :
297+ audio_content = fin .read ()
298+ audio = DiarizeAudio (encoding = codec , sample_rate = sampling_rate , language_code = language_code ,
299+ content = base64 .b64encode (audio_content ).decode ('utf-8' ), speakers = speakers ,
300+ merge_segments = merge_segments , audio_type = audio_type )
301+ fout .close ()
302+ return audio
303+
304+ @staticmethod
305+ def from_json (content_str ):
306+ content = json .loads (content_str )
307+ audio = DiarizeAudio (encoding = content ['encoding' ], sample_rate = content ['sample_rate' ],
308+ language_code = content ['language_code' ], content = content ['content' ],
309+ speakers = content ['speakers' ], merge_segments = content ['merge_segments' ],
310+ audio_type = content ['audio_type' ])
311+ return audio
0 commit comments