changeset 295:49082909193c

Rename AudioDataSource as AudioReader
author Amine Sehili <amine.sehili@gmail.com>
date Mon, 07 Oct 2019 20:44:57 +0100
parents 76b473409a46
children 5af0974b3446
files auditok/core.py auditok/util.py
diffstat 2 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/core.py	Sun Oct 06 21:12:02 2019 +0200
+++ b/auditok/core.py	Mon Oct 07 20:44:57 2019 +0100
@@ -10,7 +10,7 @@
 """
 import os
 import math
-from auditok.util import AudioDataSource, DataValidator, AudioEnergyValidator
+from auditok.util import AudioReader, DataValidator, AudioEnergyValidator
 from auditok.io import check_audio_data, to_file, player_for, get_audio_source
 from auditok.exceptions import TooSamllBlockDuration
 
@@ -49,7 +49,7 @@
 
     :Parameters:
 
-    input: str, bytes, AudioSource, AudioRegion, AudioDataSource
+    input: str, bytes, AudioSource, AudioRegion, AudioReader
         input audio data. If str, it should be a path to an existing audio
         file. If bytes, input is considered as raw audio data.
     min_dur: float
@@ -108,7 +108,7 @@
     if max_silence < 0:
         raise ValueError("'max_silence' ({}) must be >= 0".format(max_silence))
 
-    if isinstance(input, AudioDataSource):
+    if isinstance(input, AudioReader):
         source = input
         analysis_window = source.block_dur
     else:
@@ -129,7 +129,7 @@
             params["channels"] = input.ch
             input = bytes(input)
         try:
-            source = AudioDataSource(
+            source = AudioReader(
                 input, block_dur=analysis_window, **params
             )
         except TooSamllBlockDuration as exc:
--- a/auditok/util.py	Sun Oct 06 21:12:02 2019 +0200
+++ b/auditok/util.py	Mon Oct 07 20:44:57 2019 +0100
@@ -50,6 +50,7 @@
     "StringDataSource",
     "ADSFactory",
     "AudioDataSource",
+    "AudioReader",
     "AudioEnergyValidator",
 ]
 
@@ -838,9 +839,9 @@
         return getattr(self._audio_source, name)
 
 
-class AudioDataSource(DataSource):
+class AudioReader(DataSource):
     """
-    Base class for AudioDataSource objects.
+    Base class for AudioReader objects.
     It inherits from DataSource and encapsulates an AudioSource object.
     """
 
@@ -876,7 +877,7 @@
         if self.max_read is not None:
             max_read = "{:.3f}".format(self.max_read)
         return (
-            "AudioDataSource(source, block_dur={block_dur}, "
+            "AudioReader(source, block_dur={block_dur}, "
             "hop_dur={hop_dur}, record={rewindable}, "
             "max_read={max_read})"
         ).format(
@@ -919,11 +920,15 @@
     def __getattr__(self, name):
         if name in ("data", "rewind") and not self.rewindable:
             raise AttributeError(
-                "'AudioDataSource' has no attribute '{}'".format(name)
+                "'AudioReader' has no attribute '{}'".format(name)
             )
         try:
             return getattr(self._audio_source, name)
         except AttributeError:
             raise AttributeError(
-                "'AudioDataSource' has no attribute '{}'".format(name)
+                "'AudioReader' has no attribute '{}'".format(name)
             )
+
+# Keep AudioDataSource for compatibility
+# Remove in a future version when ADSFactory is dropped
+AudioDataSource = AudioReader
\ No newline at end of file