# HG changeset patch # User Amine Sehili # Date 1566498148 -7200 # Node ID 56ff493c2b9759064f541eaaa3f8faa7c7e01b29 # Parent 936511b60745cc5d024d9d52e54d19d705450631 Implement __truediv__ in AudioRegion diff -r 936511b60745 -r 56ff493c2b97 auditok/core.py --- a/auditok/core.py Tue Aug 20 20:26:04 2019 +0100 +++ b/auditok/core.py Thu Aug 22 20:22:28 2019 +0200 @@ -631,6 +631,18 @@ def __rmul__(self, n): return self * n + def __truediv__(self, n): + if not isinstance(n, int) or n <= 0: + raise TypeError( + "AudioRegion can only be divided by a positive int" + ) + samples_per_sub_region = round(len(self) / n) + 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) + return sub_regions + def __eq__(self, other): if other is self: return True