1+ import asyncio
2+
3+ import pytest
4+
15from vision_agents .plugins import funasr
26
37
8+ class _FakeAutoModel :
9+ pass
10+
11+
12+ class _FakeSamples :
13+ def __init__ (self , size = 0 ):
14+ self .size = size
15+
16+
17+ class _FakePcmData :
18+ def __init__ (
19+ self ,
20+ * ,
21+ samples = None ,
22+ sample_rate = 16000 ,
23+ channels = 1 ,
24+ format = None ,
25+ duration_ms = 0 ,
26+ ):
27+ self .samples = samples if samples is not None else _FakeSamples ()
28+ self .sample_rate = sample_rate
29+ self .channels = channels
30+ self .format = format
31+ self .duration_ms = duration_ms
32+
33+ def resample (self , sample_rate ):
34+ self .sample_rate = sample_rate
35+ return self
36+
37+ def to_float32 (self ):
38+ return self
39+
40+ def append (self , audio_data ):
41+ return audio_data
42+
43+
44+ class _ExplodingPcmData :
45+ samples = _FakeSamples (size = 1 )
46+
47+ def resample (self , sample_rate ):
48+ raise AssertionError ("unexpected audio bug" )
49+
50+
451class TestSTT :
552 """Unit tests for the FunASR STT plugin (no model loaded)."""
653
@@ -24,3 +71,24 @@ def test_custom_params(self):
2471 assert stt .language == "zh"
2572 assert stt .device == "cuda"
2673 assert stt .use_itn is False
74+
75+ def test_process_audio_raises_unexpected_buffer_errors (self ):
76+ stt = funasr .STT (client = _FakeAutoModel ())
77+
78+ with pytest .raises (AssertionError , match = "unexpected audio bug" ):
79+ asyncio .run (stt .process_audio (_ExplodingPcmData (), participant = object ()))
80+
81+ def test_process_buffer_raises_unexpected_transcription_errors (self ):
82+ stt = funasr .STT (client = _FakeAutoModel ())
83+ stt ._audio_buffer = _FakePcmData (
84+ samples = _FakeSamples (size = 16000 ),
85+ duration_ms = 1000 ,
86+ )
87+
88+ async def raise_unexpected_error (* , audio_array ):
89+ raise AssertionError ("unexpected transcription bug" )
90+
91+ stt ._transcribe = raise_unexpected_error
92+
93+ with pytest .raises (AssertionError , match = "unexpected transcription bug" ):
94+ asyncio .run (stt ._process_buffer (participant = object ()))
0 commit comments