# HG changeset patch # User Amine Sehili # Date 1546547785 -3600 # Node ID e1fd49a24b04d1a36b2320d170bc4d1980411fd9 # Parent c4e233ffd3553e20e24edc42d109007fc6c4938b Update duration computation diff -r c4e233ffd355 -r e1fd49a24b04 auditok/core.py --- a/auditok/core.py Thu Jan 03 21:19:35 2019 +0100 +++ b/auditok/core.py Thu Jan 03 21:36:25 2019 +0100 @@ -35,8 +35,6 @@ """ self._data = data self._start = start - self._duration = len(data) / (sampling_rate * sample_width * channels) - self._end = start + self._duration self._sampling_rate = sampling_rate self._sample_width = sample_width self._channels = channels @@ -47,16 +45,20 @@ @property def end(self): - return self._end + return self.start + self.duration @property def duration(self): - """Region duration in seconds""" - return self._duration + """ + Returns region duration in seconds. + """ + return len(self._data) / (self.sampling_rate * + self.sample_width * + self.channels) @property def sampling_rate(self): - return self._sample_width + return self._sampling_rate @property def sr(self): @@ -79,8 +81,10 @@ return self._channels def __len__(self): - """Region duration in milliseconds""" - return int(self._duration * 1000) + """ + Rerurns region duration in milliseconds. + """ + return round(self.duration * 1000) def __bytes__(self): return self._data