feat/ 添加app-expo三种环境切换,待测试 调整tts
This commit is contained in:
@@ -26,11 +26,41 @@ from app.features.conversation.ws.profile_collector import (
|
||||
get_missing_profile_fields,
|
||||
)
|
||||
from app.features.user.models import User
|
||||
from app.core.dependencies import get_asr_provider
|
||||
from app.core.dependencies import get_asr_provider, get_tts_provider
|
||||
from app.features.memoir.state_service import get_or_create_state
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
async def _send_tts_audio(conversation_id: str, text: str) -> None:
|
||||
"""Synthesize text to speech and send TTS_AUDIO if successful."""
|
||||
try:
|
||||
tts = get_tts_provider()
|
||||
audio_bytes = await tts.synthesize(text)
|
||||
if not audio_bytes:
|
||||
logger.warning(
|
||||
"TTS skipped: synthesize returned empty. Check TTS config in .env"
|
||||
)
|
||||
return
|
||||
await manager.send_message(conversation_id, {
|
||||
"type": MessageType.TTS_AUDIO,
|
||||
"conversation_id": conversation_id,
|
||||
"data": {
|
||||
"audio_base64": base64.b64encode(audio_bytes).decode("utf-8"),
|
||||
"format": "mp3",
|
||||
},
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
})
|
||||
except Exception as e:
|
||||
err_str = str(e)
|
||||
if "PkgExhausted" in err_str:
|
||||
logger.warning(
|
||||
"TTS skipped: 腾讯云语音合成资源包已用尽,请在控制台购买或开通后付费: %s",
|
||||
err_str[:100],
|
||||
)
|
||||
else:
|
||||
logger.error("TTS synthesize failed: %s", e)
|
||||
|
||||
# ── Agent 实例(从 ConnectionManager 移出) ─────────────────────
|
||||
conversation_agent = ConversationAgent()
|
||||
memory_agent = MemoryAgent()
|
||||
@@ -447,6 +477,7 @@ async def process_user_message(
|
||||
"data": {"text": response_text, "index": i, "total": len(responses)},
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
})
|
||||
await _send_tts_audio(conversation_id, response_text)
|
||||
if i < len(responses) - 1:
|
||||
await asyncio.sleep(0.5)
|
||||
return
|
||||
@@ -498,6 +529,7 @@ async def process_user_message(
|
||||
"data": {"text": response_text, "index": i, "total": len(responses)},
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
})
|
||||
await _send_tts_audio(conversation_id, response_text)
|
||||
if i < len(responses) - 1:
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user