changeset 81:22769f0c8d4a

Add AudioRegion class
author Amine Sehili <amine.sehili@gmail.com>
date Wed, 02 Jan 2019 21:09:29 +0100
parents b3dffec14dfb
children ef6d0f0a9cd2
files auditok/core.py
diffstat 1 files changed, 61 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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():