package com.xly.tts.service; import com.xly.tts.bean.TTSResponseDTO; import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class LocalAudioCache { // 内部存储结构:cacheKey_index -> { "text":"...", "audio":"base64" } private static final Map> CACHE = new ConcurrentHashMap<>(); // 存储:一段文字 + 一段音频 public static void addPiece(String cacheKey, int index, String text, String audioBase64) { String key = cacheKey + "_" + index; CACHE.put(key, Map.of("text", text, "audio", audioBase64)); } // 获取:一段文字 + 音频 public static Map getPiece(String cacheKey, int index) { return CACHE.get(cacheKey + "_" + index); } }