diff tests/test_core.py @ 415:e26dcf224846

implement 'make_silence'
author Amine Sehili <amine.sehili@gmail.com>
date Wed, 16 Oct 2024 20:08:37 +0200
parents 9f83c1ecb03b
children 14efef6f4bae
line wrap: on
line diff
--- a/tests/test_core.py	Tue Oct 15 21:56:12 2024 +0200
+++ b/tests/test_core.py	Wed Oct 16 20:08:37 2024 +0200
@@ -8,7 +8,7 @@
 import numpy as np
 import pytest
 
-from auditok import AudioParameterError, AudioRegion, load, split
+from auditok import AudioParameterError, AudioRegion, load, make_silence, split
 from auditok.core import (
     _duration_to_nb_windows,
     _make_audio_region,
@@ -77,6 +77,34 @@
 
 
 @pytest.mark.parametrize(
+    "duration, sampling_rate, sample_width, channels",
+    [
+        (1.05, 16000, 1, 1),  # mono_16K_1byte
+        (1.5, 16000, 2, 1),  # mono_16K_2byte
+        (1.0001, 44100, 2, 2),  # stereo_44100_2byte
+        (1.000005, 48000, 2, 3),  # 3channel_48K_2byte
+        (1.0001, 48000, 4, 4),  # 4channel_48K_4byte
+        (0, 48000, 4, 4),  # 4channel_4K_4byte_0sec
+    ],
+    ids=[
+        "mono_16K_1byte",
+        "mono_16K_2byte",
+        "stereo_44100_2byte",
+        "3channel_48000_2byte",
+        "4channel_48K_4byte",
+        "4channel_4K_4byte_0sec",
+    ],
+)
+def test_make_silence(duration, sampling_rate, sample_width, channels):
+    silence = make_silence(duration, sampling_rate, sample_width, channels)
+    size = round(duration * sampling_rate) * sample_width * channels
+    expected_data = b"\0" * size
+    expected_duration = size / (sampling_rate * sample_width * channels)
+    assert silence.duration == expected_duration
+    assert silence.data == expected_data
+
+
+@pytest.mark.parametrize(
     "duration, analysis_window, round_fn, expected, kwargs",
     [
         (0, 1, None, 0, None),  # zero_duration