Files
life-echo/api/app/features/conversation/tts_delivery.py

29 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
对话 TTS 音频 URL 下发到客户端。
与回忆录章节图片一致:私有桶下不能把「直链」当公开可读 URL 使用,应对 COS object key
生成预签名下载地址后再交给 App参见 `normalize_image_assets_for_api` 中的 `get_download_url`)。
持久化DB / Redis仍保存 upload 返回的 canonical URL仅在 API 响应与 WS 实时下发时做 presign。
"""
from __future__ import annotations
from app.core.cos_url_keys import presign_tts_urls_for_playback
from app.ports.storage import ObjectStorage
def apply_presigned_tts_urls_to_messages(
messages: list[dict],
storage: ObjectStorage | None,
) -> None:
"""就地改写助手消息的 `ttsAudioUrls` 为预签名 URL无 storage 时不变。"""
if not storage:
return
for m in messages:
tts = m.get("ttsAudioUrls")
if not isinstance(tts, list) or not tts:
continue
str_urls = [x for x in tts if isinstance(x, str)]
m["ttsAudioUrls"] = presign_tts_urls_for_playback(str_urls, storage)