'commit'
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -17,6 +17,8 @@ logger = logging.getLogger(__name__)
|
||||
from Util.XueBanUtil import get_xueban_response_async
|
||||
from Util.ASRClient import ASRClient
|
||||
from Util.ObsUtil import ObsUploader
|
||||
# 新增导入TTSService
|
||||
from Util.TTSService import TTSService
|
||||
|
||||
|
||||
@router.post("/xueban/upload-audio")
|
||||
@@ -49,11 +51,36 @@ async def upload_audio(file: UploadFile = File(...)):
|
||||
os.remove(temp_file_path)
|
||||
logger.info(f"临时文件已删除: {temp_file_path}")
|
||||
|
||||
# 返回识别结果
|
||||
# 使用大模型生成反馈
|
||||
logger.info(f"使用大模型生成反馈,输入文本: {asr_result['text']}")
|
||||
response_generator = get_xueban_response_async(asr_result['text'], stream=False)
|
||||
feedback_text = ""
|
||||
async for chunk in response_generator:
|
||||
feedback_text += chunk
|
||||
logger.info(f"大模型反馈生成完成: {feedback_text}")
|
||||
|
||||
# 使用TTS生成语音
|
||||
tts_service = TTSService()
|
||||
tts_temp_file = os.path.join(tempfile.gettempdir(), f"tts_{timestamp}.mp3")
|
||||
success = tts_service.synthesize(feedback_text, output_file=tts_temp_file)
|
||||
if not success:
|
||||
raise Exception("TTS语音合成失败")
|
||||
logger.info(f"TTS语音合成成功,文件保存至: {tts_temp_file}")
|
||||
|
||||
# 上传TTS音频文件到OBS
|
||||
tts_audio_url = upload_file_to_obs(tts_temp_file)
|
||||
os.remove(tts_temp_file) # 删除临时TTS文件
|
||||
logger.info(f"TTS文件已上传至OBS: {tts_audio_url}")
|
||||
|
||||
# 返回结果,包含ASR文本和TTS音频URL
|
||||
return JSONResponse(content={
|
||||
"success": True,
|
||||
"message": "音频识别成功",
|
||||
"data": asr_result
|
||||
"message": "音频处理和语音反馈生成成功",
|
||||
"data": {
|
||||
"asr_text": asr_result['text'],
|
||||
"feedback_text": feedback_text,
|
||||
"audio_url": tts_audio_url
|
||||
}
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user