changeset 385:edcc102fb33f

Update documentation and configuration
author Amine Sehili <amine.sehili@gmail.com>
date Tue, 02 Mar 2021 20:10:50 +0100
parents c030134b7870
children 059599823c34
files .pre-commit-config.yaml CHANGELOG auditok/core.py auditok/util.py doc/_static/css/custom_style.css doc/conf.py doc/examples.rst pyproject.toml
diffstat 8 files changed, 51 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/.pre-commit-config.yaml	Mon Mar 01 23:11:49 2021 +0100
+++ b/.pre-commit-config.yaml	Tue Mar 02 20:10:50 2021 +0100
@@ -1,6 +1,6 @@
 repos:
 -   repo: https://github.com/psf/black
-    rev: stable
+    rev: 20.8b1
     hooks:
     - id: black
       language_version: python3.7
--- a/CHANGELOG	Mon Mar 01 23:11:49 2021 +0100
+++ b/CHANGELOG	Tue Mar 02 20:10:50 2021 +0100
@@ -10,6 +10,7 @@
 - Choose which channel(s) to use for tokenization
 - Save multi-channel audio data
 - Refactor code in all modules
+- Use genty for tests
 - Improve documentation
 - Use ArgumentParser instead of OptionParser in command-line script
 - Clean up command-line script and move functions and workers to dedicated modules
--- a/auditok/core.py	Mon Mar 01 23:11:49 2021 +0100
+++ b/auditok/core.py	Tue Mar 02 20:10:50 2021 +0100
@@ -240,9 +240,7 @@
         validator = AudioEnergyValidator(
             energy_threshold, source.sw, source.ch, use_channel=use_channel
         )
-    mode = (
-        StreamTokenizer.DROP_TRAILING_SILENCE if drop_trailing_silence else 0
-    )
+    mode = StreamTokenizer.DROP_TRAILING_SILENCE if drop_trailing_silence else 0
     if strict_min_dur:
         mode |= StreamTokenizer.STRICT_MIN_LENGTH
     min_length = _duration_to_nb_windows(min_dur, analysis_window, math.ceil)
@@ -532,8 +530,7 @@
 
 
 class _AudioRegionMetadata(dict):
-    """A class to store `AudioRegion`'s metadata.
-    """
+    """A class to store `AudioRegion`'s metadata."""
 
     def __getattr__(self, name):
         if name in self:
@@ -610,8 +607,7 @@
 
     @meta.setter
     def meta(self, new_meta):
-        """Meta data of audio region.
-        """
+        """Meta data of audio region."""
         self._meta = _AudioRegionMetadata(new_meta)
 
     @classmethod
@@ -658,8 +654,7 @@
 
     @property
     def millis(self):
-        """A view to slice audio region by milliseconds (using ``region.millis[start:end]``).
-        """
+        """A view to slice audio region by milliseconds (using ``region.millis[start:end]``)."""
         return self._millis_view
 
     @property
@@ -673,38 +668,32 @@
 
     @property
     def sampling_rate(self):
-        """Samling rate of audio data.
-        """
+        """Samling rate of audio data."""
         return self._sampling_rate
 
     @property
     def sr(self):
-        """Samling rate of audio data, alias for `sampling_rate`.
-        """
+        """Samling rate of audio data, alias for `sampling_rate`."""
         return self._sampling_rate
 
     @property
     def sample_width(self):
-        """Number of bytes per sample, one channel considered.
-        """
+        """Number of bytes per sample, one channel considered."""
         return self._sample_width
 
     @property
     def sw(self):
-        """Number of bytes per sample, alias for `sampling_rate`.
-        """
+        """Number of bytes per sample, alias for `sampling_rate`."""
         return self._sample_width
 
     @property
     def channels(self):
-        """Number of channels of audio data.
-        """
+        """Number of channels of audio data."""
         return self._channels
 
     @property
     def ch(self):
-        """Number of channels of audio data, alias for `channels`.
-        """
+        """Number of channels of audio data, alias for `channels`."""
         return self._channels
 
     def play(self, progress_bar=False, player=None, **progress_bar_kwargs):
@@ -730,9 +719,7 @@
             self._data, progress_bar=progress_bar, **progress_bar_kwargs
         )
 
-    def save(
-        self, file, audio_format=None, exists_ok=True, **audio_parameters
-    ):
+    def save(self, file, audio_format=None, exists_ok=True, **audio_parameters):
         """
         Save audio region to file.
 
@@ -918,8 +905,7 @@
 
     @property
     def samples(self):
-        """Audio region as arrays of samples, one array per channel.
-        """
+        """Audio region as arrays of samples, one array per channel."""
         if self._samples is None:
             self._samples = signal.to_array(
                 self._data, self.sample_width, self.channels
@@ -1005,9 +991,7 @@
 
     def __truediv__(self, n):
         if not isinstance(n, int) or n <= 0:
-            raise TypeError(
-                "AudioRegion can only be divided by a positive int"
-            )
+            raise TypeError("AudioRegion can only be divided by a positive int")
         samples_per_sub_region, rest = divmod(len(self), n)
         onset = 0
         sub_regions = []
@@ -1232,9 +1216,7 @@
             )
 
         if min_length <= 0 or min_length > max_length:
-            err_msg = (
-                "'min_length' must be > 0 and <= 'max_length' (value={0})"
-            )
+            err_msg = "'min_length' must be > 0 and <= 'max_length' (value={0})"
             raise ValueError(err_msg.format(min_length))
 
         if max_continuous_silence >= max_length:
--- a/auditok/util.py	Mon Mar 01 23:11:49 2021 +0100
+++ b/auditok/util.py	Tue Mar 02 20:10:50 2021 +0100
@@ -509,9 +509,7 @@
             "asrc", None
         )
         kwargs["fn"] = kwargs.pop("filename", None) or kwargs.pop("fn", None)
-        kwargs["db"] = kwargs.pop("data_buffer", None) or kwargs.pop(
-            "db", None
-        )
+        kwargs["db"] = kwargs.pop("data_buffer", None) or kwargs.pop("db", None)
 
         record = kwargs.pop("record", False)
         if not record:
--- a/doc/_static/css/custom_style.css	Mon Mar 01 23:11:49 2021 +0100
+++ b/doc/_static/css/custom_style.css	Tue Mar 02 20:10:50 2021 +0100
@@ -1,3 +1,7 @@
+div.wy-side-nav-search {
+    background-color: #000000;
+}
+
 div.wy-side-nav-search .version {
     color: #DDDDDD;
     font-weight: bold;
--- a/doc/conf.py	Mon Mar 01 23:11:49 2021 +0100
+++ b/doc/conf.py	Tue Mar 02 20:10:50 2021 +0100
@@ -137,7 +137,7 @@
     html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
 html_theme_options = {
     "logo_only": True,
-    "style_nav_header_background": "black",
+    "style_nav_header_background": "#000000",
 }
 
 # Theme options are theme-specific and customize the look and feel of a theme
--- a/doc/examples.rst	Mon Mar 01 23:11:49 2021 +0100
+++ b/doc/examples.rst	Tue Mar 02 20:10:50 2021 +0100
@@ -1,5 +1,5 @@
-Loading audio data
-------------------
+Load audio data
+---------------
 
 Audio data is loaded with the :func:`load` function which can read from audio
 files, the microphone or use raw audio data.
@@ -7,15 +7,15 @@
 From a file
 ===========
 
-If the first argument of :func:`load` is a string, it should be a path to an audio
-file.
+If the first argument of :func:`load` is a string, it should be a path to an
+audio file.
 
 .. code:: python
 
     import auditok
     region = auditok.load("audio.ogg")
 
-If input file contains a raw (headerless) audio data, passing `audio_format="raw"`
+If input file contains raw (headerless) audio data, passing `audio_format="raw"`
 and other audio parameters (`sampling_rate`, `sample_width` and `channels`) is
 mandatory. In the following example we pass audio parameters with their short
 names:
@@ -42,6 +42,8 @@
     data = b"\0" * sr * sw * ch
     region = auditok.load(data, sr=sr, sw=sw, ch=ch)
     print(region)
+    # alternatively you can use
+    #region = auditok.AudioRegion(data, sr, sw, ch)
 
 output:
 
@@ -74,15 +76,30 @@
 Skip part of audio data
 =======================
 
-If the `skip` parameter is > 0, :func:`load` will skip that leading amount of audio
-data:
+If the `skip` parameter is > 0, :func:`load` will skip that amount  in seconds
+of leading audio data:
 
 .. code:: python
 
     import auditok
     region = auditok.load("audio.ogg", skip=2) # skip the first 2 seconds
 
-This argument must be 0 when reading from the microphone.
+This argument must be 0 when reading data from the microphone.
+
+
+Limit the amount of read audio
+==============================
+
+If the `max_read` parameter is > 0, :func:`load` will read at most that amount
+in seconds of audio data:
+
+.. code:: python
+
+    import auditok
+    region = auditok.load("audio.ogg", max_read=5)
+    assert region.duration <= 5
+
+This argument is mandatory when reading data from the microphone.
 
 
 Basic split example
@@ -188,8 +205,8 @@
 seconds with the `max_read` argument.
 
 
-Accessing recorded data after split
------------------------------------
+Access recorded data after split
+--------------------------------
 
 Using a :class:`Recorder` object you can get hold of acquired audio data:
 
@@ -362,7 +379,7 @@
     assert len(samples) == region.channels
 
 
-If `numpy` is not installed you can use:
+If `numpy` is installed you can use:
 
 .. code:: python
 
--- a/pyproject.toml	Mon Mar 01 23:11:49 2021 +0100
+++ b/pyproject.toml	Tue Mar 02 20:10:50 2021 +0100
@@ -1,5 +1,5 @@
 [tool.black]
-line-length = 79
+line-length = 80
 include = '\.pyi?$'
 exclude = '''
 /(