# HG changeset patch # User Amine Sehili # Date 1546459769 -3600 # Node ID 22769f0c8d4ac747b76cd46636181187885ea426 # Parent b3dffec14dfbc855800a95884e0d86e032ee2574 Add AudioRegion class diff -r b3dffec14dfb -r 22769f0c8d4a auditok/core.py --- a/auditok/core.py Thu Nov 01 07:05:16 2018 +0100 +++ b/auditok/core.py Wed Jan 02 21:09:29 2019 +0100 @@ -11,7 +11,67 @@ from auditok.util import DataValidator -__all__ = ["StreamTokenizer"] +__all__ = ["AudioRegion", "StreamTokenizer"] + + +class AudioRegion(object): + + def __init__(self, data, start, sampling_rate, sample_width, channels): + """ + A class for detected audio events. + + :Parameters: + + data: bytes + audio data + start: float + start time in seconds + samling_rate: int + sampling rate of audio data + sample_width: int + number of bytes of one audio sample + channels: int + number of channels of audio data + """ + 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 + + @property + def start(self): + return self._start + + @property + def end(self): + return self._end + + @property + def sampling_rate(self): + return self._sample_width + + @property + def sr(self): + return self._sampling_rate + + @property + def sample_width(self): + return self._sample_width + + @property + def sw(self): + return self._sample_width + + @property + def channels(self): + return self._channels + + @property + def ch(self): + return self._channels class StreamTokenizer():