changeset 150:6c1a11cf9e6a

Refactor AudioSource
author Amine Sehili <amine.sehili@gmail.com>
date Fri, 22 Feb 2019 20:55:19 +0100
parents 81413c14c5bb
children ace5ee1f185e
files auditok/io.py
diffstat 1 files changed, 13 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/io.py	Thu Feb 21 20:53:17 2019 +0100
+++ b/auditok/io.py	Fri Feb 22 20:55:19 2019 +0100
@@ -203,7 +203,7 @@
     return _array_to_bytes(buffer[use_channel::channels])
 
 
-class AudioSource:
+class AudioSource():
     """ 
     Base class for audio source objects.
 
@@ -220,44 +220,32 @@
             Default = 2.
 
         `channels` : int
-            Number of channels of audio stream. The current version supports
-            only mono audio streams (i.e. one channel).
+            Number of channels of audio stream.
     """
 
-    __metaclass__ = ABCMeta
+    def __init__(self, sampling_rate=DEFAULT_SAMPLE_RATE,
+                 sample_width=DEFAULT_SAMPLE_WIDTH,
+                 channels=DEFAULT_NB_CHANNELS):
 
-    def __init__(
-        self,
-        sampling_rate=DEFAULT_SAMPLE_RATE,
-        sample_width=DEFAULT_SAMPLE_WIDTH,
-        channels=DEFAULT_NB_CHANNELS,
-    ):
-
-        if sample_width not in (1, 2, 4):
-            raise AudioParameterError(
-                "Sample width must be one of: 1, 2 or 4 (bytes)"
-            )
-
-        if channels != 1:
-            raise AudioParameterError("Only mono audio is currently supported")
+        if not sample_width in (1, 2, 4):
+            raise AudioParameterError("Sample width must be one of: 1, 2 or 4 (bytes)")
 
         self._sampling_rate = sampling_rate
         self._sample_width = sample_width
         self._channels = channels
 
-    @abstractmethod
     def is_open(self):
         """ Return True if audio source is open, False otherwise """
+        raise NotImplementedError
 
-    @abstractmethod
     def open(self):
         """ Open audio source """
+        raise NotImplementedError
 
-    @abstractmethod
     def close(self):
         """ Close audio source """
+        raise NotImplementedError
 
-    @abstractmethod
     def read(self, size):
         """
         Read and return `size` audio samples at most.
@@ -269,12 +257,14 @@
 
         :Returns:
 
-            Audio data as a string of length 'N' * 'sample_width' * 'channels', where 'N' is:
+            Audio data as a string of length `N * sample_width * channels`,
+            where `N` is:
 
             - `size` if `size` < 'left_samples'
 
             - 'left_samples' if `size` > 'left_samples' 
         """
+        raise NotImplementedError
 
     def get_sampling_rate(self):
         """ Return the number of samples per second of audio stream """