Files
operating-room-monitor-server/backend/tests/test_baidu_asr_fallback.py
Kevin 1af442481e 重组为 backend/clients/docs 三层结构,并清理 git 污染。
将后端迁入 backend/,完善根目录 .gitignore,删除误提交的 .mypy_cache 缓存文件。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 16:02:25 +08:00

30 lines
920 B
Python
Raw 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"