-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathtest_silero_vad_session_sharing.py
More file actions
46 lines (31 loc) · 1.28 KB
/
Copy pathtest_silero_vad_session_sharing.py
File metadata and controls
46 lines (31 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# Copyright (c) 2024–2025, Daily
#
# SPDX-License-Identifier: BSD 2-Clause License
#
"""Tests that Silero VAD analyzers share one ONNX session without sharing state."""
import unittest
import numpy as np
from pipecat.audio.vad.silero import SileroVADAnalyzer
def _analyzer() -> SileroVADAnalyzer:
analyzer = SileroVADAnalyzer()
analyzer.set_sample_rate(16000)
return analyzer
def _frame() -> bytes:
rng = np.random.default_rng(0)
return (rng.normal(0, 0.3, 512) * 32767).astype("int16").tobytes()
class TestSileroVADSessionSharing(unittest.TestCase):
def test_analyzers_share_one_session(self):
self.assertIs(_analyzer()._model.session, _analyzer()._model.session)
def test_state_stays_per_analyzer(self):
frame = _frame()
first, second = _analyzer(), _analyzer()
baseline = np.ravel(first.voice_confidence(frame))[0]
self.assertEqual(baseline, np.ravel(second.voice_confidence(frame))[0])
# Advancing one analyzer must not move the other
for _ in range(5):
second.voice_confidence(frame)
self.assertEqual(baseline, np.ravel(first.voice_confidence(frame))[0])
self.assertNotEqual(baseline, np.ravel(second.voice_confidence(frame))[0])
if __name__ == "__main__":
unittest.main()