Files
operating-room-monitor-server/tests/test_baidu_asr_fallback.py
2026-04-28 10:41:48 +08:00

30 lines
920 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""百度 ASR3301 时 WAV 重试。"""
from __future__ import annotations
import array
from unittest.mock import MagicMock
from app.config import Settings
from app.services.baidu_speech import BaiduSpeechService
def test_asr_pcm_or_wav_fallback_retries_on_3301() -> None:
ok = {"err_no": 0, "result": [""]}
pcm = array.array("h", [100] * 800).tobytes()
client = MagicMock()
client.asr = MagicMock(side_effect=[{"err_no": 3301, "err_msg": "q"}, ok])
svc = BaiduSpeechService(
app_settings=Settings(
BAIDU_APP_ID="1",
BAIDU_API_KEY="k",
BAIDU_SECRET_KEY="s",
)
)
svc._client = client # type: ignore[attr-defined]
r = svc.asr_16k_mono_pcm_or_wav_fallback(pcm)
assert r == ok
assert client.asr.call_count == 2
assert client.asr.call_args_list[0][0][1] == "pcm"
assert client.asr.call_args_list[1][0][1] == "wav"