Mercurial > hg > auditok
changeset 253:b9085fc3fc5f
Fix bug in __truediv__
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Fri, 30 Aug 2019 21:15:27 +0100 |
parents | d3a815e1b001 |
children | 1f04ffd132ae |
files | auditok/core.py |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/auditok/core.py Fri Aug 30 20:50:12 2019 +0100 +++ b/auditok/core.py Fri Aug 30 21:15:27 2019 +0100 @@ -689,11 +689,17 @@ raise TypeError( "AudioRegion can only be divided by a positive int" ) - samples_per_sub_region = round(len(self) / n) + samples_per_sub_region, rest = divmod(len(self), n) + onset = 0 sub_regions = [] - for onset in range(0, len(self), samples_per_sub_region): - sub_region = self[onset : onset + samples_per_sub_region] - sub_regions.append(sub_region) + while onset < len(self): + offset = 0 + if rest > 0: + offset = 1 + rest -= 1 + offset += onset + samples_per_sub_region + sub_regions.append(self[onset:offset]) + onset = offset return sub_regions def __eq__(self, other):