修改设备端对接

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,35 @@
import asyncio
from typing import Dict, List, Optional
class TargetAudioCache:
def __init__(self):
self.audio_data_cache: Dict[str, List[bytes]] = {}
self.lock = asyncio.Lock()
async def add_audio_data(self, device_id: str, audio_data: bytes):
async with self.lock:
if device_id not in self.audio_data_cache:
self.audio_data_cache[device_id] = []
self.audio_data_cache[device_id].append(audio_data)
async def get_audio_data(self, device_id: str) -> Optional[bytes]:
async with self.lock:
if device_id not in self.audio_data_cache:
return None
# 合并所有音频数据
combined_audio = b''.join(self.audio_data_cache[device_id])
return combined_audio
async def clear_audio_data(self, device_id: str):
async with self.lock:
if device_id in self.audio_data_cache:
del self.audio_data_cache[device_id]
async def has_cached_audio(self, device_id: str) -> bool:
async with self.lock:
return device_id in self.audio_data_cache and len(self.audio_data_cache[device_id]) > 0
# 单例实例
target_audio_cache = TargetAudioCache()