ruff
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import base64
|
||||
|
||||
from src.config.config import global_config, model_config
|
||||
from src.llm_models.utils_model import LLMRequest
|
||||
|
||||
from src.common.logger import get_logger
|
||||
from rich.traceback import install
|
||||
|
||||
install(extra_lines=3)
|
||||
|
||||
logger = get_logger("chat_voice")
|
||||
|
||||
|
||||
async def get_voice_text(voice_base64: str) -> str:
|
||||
"""获取音频文件描述"""
|
||||
"""获取音频文件转录文本"""
|
||||
if not global_config.voice.enable_asr:
|
||||
logger.warning("语音识别未启用,无法处理语音消息")
|
||||
return "[语音]"
|
||||
@@ -20,11 +20,10 @@ async def get_voice_text(voice_base64: str) -> str:
|
||||
if text is None:
|
||||
logger.warning("未能生成语音文本")
|
||||
return "[语音(文本生成失败)]"
|
||||
|
||||
|
||||
logger.debug(f"描述是{text}")
|
||||
|
||||
return f"[语音:{text}]"
|
||||
except Exception as e:
|
||||
logger.error(f"语音转文字失败: {str(e)}")
|
||||
return "[语音]"
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class BaseClient:
|
||||
:return: 嵌入响应
|
||||
"""
|
||||
raise RuntimeError("This method should be overridden in subclasses")
|
||||
|
||||
|
||||
async def get_audio_transcriptions(
|
||||
self,
|
||||
model_info: ModelInfo,
|
||||
|
||||
@@ -551,7 +551,7 @@ class OpenaiClient(BaseClient):
|
||||
raw_response = await self.client.audio.transcriptions.create(
|
||||
model=model_info.model_identifier,
|
||||
file=("audio.wav", io.BytesIO(base64.b64decode(audio_base64))),
|
||||
extra_body=extra_params
|
||||
extra_body=extra_params,
|
||||
)
|
||||
except APIConnectionError as e:
|
||||
raise NetworkConnectionError() from e
|
||||
@@ -567,4 +567,4 @@ class OpenaiClient(BaseClient):
|
||||
raw_response,
|
||||
"响应解析失败,缺失转录文本。",
|
||||
)
|
||||
return response
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user