修改设备端对接

This commit is contained in:
HycJack
2026-04-16 21:13:06 +08:00
parent a22fcafea9
commit 602f0f7737
19 changed files with 1385 additions and 60 deletions

View File

@@ -0,0 +1,31 @@
import asyncio
from typing import Dict, List
class OfflineAudioCache:
def __init__(self):
self.offline_audio: Dict[str, List[str]] = {}
self.lock = asyncio.Lock()
async def add_audio_url(self, device_id: str, audio_url: str):
async with self.lock:
if device_id not in self.offline_audio:
self.offline_audio[device_id] = []
self.offline_audio[device_id].append(audio_url)
async def get_audio_urls(self, device_id: str) -> List[str]:
async with self.lock:
return self.offline_audio.get(device_id, [])
async def clear_audio_urls(self, device_id: str):
async with self.lock:
if device_id in self.offline_audio:
del self.offline_audio[device_id]
async def has_pending_audio(self, device_id: str) -> bool:
async with self.lock:
return device_id in self.offline_audio and len(self.offline_audio[device_id]) > 0
# 单例实例
offline_audio_cache = OfflineAudioCache()