changeset 219:d03516b85619

Raise ValueError with meaningful messages when duration parameters aren’t coherent in split
author Amine Sehili <amine.sehili@gmail.com>
date Mon, 08 Jul 2019 20:32:01 +0100
parents 41e2ce69d4f4
children ed25ee654515
files auditok/core.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/core.py	Sat Jul 06 11:32:11 2019 +0100
+++ b/auditok/core.py	Mon Jul 08 20:32:01 2019 +0100
@@ -87,6 +87,13 @@
         energy threshlod for audio activity detection, default: 50. If a custom
         validator is given, this argumemt will be ignored.
     """
+    if min_dur <= 0 or max_dur <= 0:
+        raise ValueError(
+            "min_dur ({}) and 'max_dur' ({}) must be > 0".format(
+                min_dur, max_dur
+            )
+        )
+
     if isinstance(input, AudioDataSource):
         source = input
         analysis_window = source.block_dur
@@ -125,6 +132,29 @@
         max_silence, analysis_window
     )
 
+    err_msg = "({0} second(s)) results in {1} analysis windows "
+    err_msg += "(i.e. ceil({0} / {2})) which is higher than the number "
+    err_msg += "of analysis windows ({3}) for 'max_dur' ({4} second(s))"
+    if min_length > max_length:
+        err_msg = "'min_dur' " + err_msg
+        raise ValueError(
+            err_msg.format(
+                min_dur, min_length, analysis_window, max_length, max_dur
+            )
+        )
+
+    if max_continuous_silence >= max_length:
+        err_msg = "'max_silence' " + err_msg
+        raise ValueError(
+            err_msg.format(
+                max_silence,
+                max_continuous_silence,
+                analysis_window,
+                max_length,
+                max_dur,
+            )
+        )
+
     tokenizer = StreamTokenizer(
         validator, min_length, max_length, max_continuous_silence, mode=mode
     )