feat: 语音确认、联调与运维增强
- 语音:序数解析(第一个/第二个等)、解析失败计数与 API detail.retry_remaining; 百度 ASR 固定 dev_pid 为普通话;SurgeryPipelineError 支持 extra 并入 HTTP detail。 - Demo:demo 路由与假 RTSP、客户端 index 与 README;BackendResolver 与配置调整。 - 可观测:消耗 TSV 日志、语音文件日志、终端 Markdown 辅助;相关测试与依赖更新。 - 注意:.env 仍被 gitignore,本地密钥不会进入本提交。 Made-with: Cursor
This commit is contained in:
@@ -10,6 +10,8 @@ from app.schemas import (
|
||||
SurgeryPendingConfirmationResponse,
|
||||
)
|
||||
from app.services.video.session_manager import CameraSessionManager
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
|
||||
from app.services.voice_resolution import VoiceConfirmationService, VoiceResolveResult
|
||||
from app.surgery_errors import SurgeryPipelineError
|
||||
|
||||
@@ -79,6 +81,18 @@ class SurgeryPipeline:
|
||||
def voice_status(self, surgery_id: str) -> dict[str, object] | None:
|
||||
return self._sessions.voice_status(surgery_id)
|
||||
|
||||
async def list_voice_audits(
|
||||
self,
|
||||
surgery_id: str,
|
||||
*,
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
):
|
||||
"""持久化表 `voice_confirmation_audits` 分页,用于追溯/对账/报表。"""
|
||||
return await self._voice.list_voice_audits_for_surgery(
|
||||
surgery_id, limit=limit, offset=offset
|
||||
)
|
||||
|
||||
def get_pending_confirmation_for_client(
|
||||
self, surgery_id: str
|
||||
) -> SurgeryPendingConfirmationResponse | None:
|
||||
@@ -114,3 +128,35 @@ class SurgeryPipeline:
|
||||
filename=filename,
|
||||
content_type=content_type,
|
||||
)
|
||||
|
||||
async def resolve_pending_confirmation_from_client_text(
|
||||
self,
|
||||
surgery_id: str,
|
||||
confirmation_id: str,
|
||||
recognized_text: str,
|
||||
) -> VoiceResolveResult:
|
||||
"""浏览器等客户端本机识别后的文本,解析规则与 WAV 路径一致(无需 MinIO/百度)。"""
|
||||
return await self._voice.resolve_from_recognized_text(
|
||||
surgery_id=surgery_id,
|
||||
confirmation_id=confirmation_id,
|
||||
recognized_text=recognized_text,
|
||||
)
|
||||
|
||||
async def get_pending_prompt_audio_mp3(
|
||||
self,
|
||||
surgery_id: str,
|
||||
confirmation_id: str,
|
||||
) -> bytes:
|
||||
"""待确认 `prompt_text` 的百度 TTS MP3,供模拟客户端用 Audio 直放。"""
|
||||
pending = self._sessions.get_pending_confirmation_by_id(
|
||||
surgery_id, confirmation_id
|
||||
)
|
||||
if pending is None or pending.status != "pending":
|
||||
raise SurgeryPipelineError(
|
||||
"CONFIRMATION_NOT_FOUND",
|
||||
"未找到该待确认项或已处理。",
|
||||
)
|
||||
return await run_in_threadpool(
|
||||
self._voice.synthesize_prompt_to_mp3,
|
||||
pending.prompt_text,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user