legco_ai_assistant/backend/app/services/asr_client.py

26 lines
746 B
Python

import struct
import base64
import logging
logger = logging.getLogger(__name__)
def float32_to_s16le(float32_bytes: bytes) -> bytes:
num_samples = len(float32_bytes) // 4
floats = struct.unpack(f"<{num_samples}f", float32_bytes)
int16_samples = [max(-32768, min(32767, int(f * 32767.0))) for f in floats]
return struct.pack(f"<{num_samples}h", *int16_samples)
def build_display_text(accumulated: str, current: str) -> str:
parts = [p for p in (accumulated, current) if p and p.strip()]
return " ".join(parts)
class ASRClient:
def __init__(self, settings):
self.settings = settings
async def transcribe_full(self, audio_bytes: bytes, language: str = "yue") -> str:
raise NotImplementedError