refactor(asr): 重构speech_to_text方法以接收artifacts参数

移除各ASR提供者中重复的get_current_artifacts调用,改为通过参数传递artifacts
修改base类中process_audio方法,根据combined_pcm_data长度决定是否创建artifacts
更新所有speech_to_text方法签名,添加artifacts可选参数并更新文档字符串
This commit is contained in:
huozaimengli
2026-01-29 16:39:35 +08:00
parent 15650e1a6c
commit 614b662e3d
15 changed files with 44 additions and 35 deletions
@@ -30,7 +30,7 @@ class ASRProvider(ASRProviderBase):
os.makedirs(self.output_dir, exist_ok=True)
async def speech_to_text(
self, opus_data: List[bytes], session_id: str, audio_format="opus"
self, opus_data: List[bytes], session_id: str, audio_format="opus", artifacts=None
) -> Tuple[Optional[str], Optional[str]]:
"""将语音数据转换为文本"""
if not opus_data:
@@ -43,7 +43,6 @@ class ASRProvider(ASRProviderBase):
logger.bind(tag=TAG).error("百度语音识别配置未设置,无法进行识别")
return None, None
artifacts = self.get_current_artifacts()
if artifacts is None:
return "", None