|
|
@@ -159,10 +159,15 @@ class ASRWorker:
|
|
|
|
|
|
async def _transcribe():
|
|
|
tick = 0
|
|
|
+ last_pos = 0
|
|
|
while True:
|
|
|
await asyncio.sleep(TRANSCRIBE_INTERVAL)
|
|
|
tick += 1
|
|
|
- audio = buf.get_last(BUFFER_DURATION)
|
|
|
+ total = len(buf.buffer)
|
|
|
+ if total - last_pos < 3200:
|
|
|
+ continue
|
|
|
+ context = int(0.5 * 16000)
|
|
|
+ audio = buf.buffer[max(0, last_pos - context):]
|
|
|
if len(audio) <= 1600:
|
|
|
continue
|
|
|
|
|
|
@@ -175,9 +180,11 @@ class ASRWorker:
|
|
|
logger.exception("transcription failed")
|
|
|
continue
|
|
|
|
|
|
+ new_samples = total - last_pos
|
|
|
+ last_pos = total
|
|
|
raw = result.get("text", "").strip()
|
|
|
if tick % 5 == 0:
|
|
|
- logger.info(f"[{sid}] transcribe tick={tick} raw='{raw}' buffer_samples={len(audio)}")
|
|
|
+ logger.info(f"[{sid}] transcribe tick={tick} raw='{raw}' new={new_samples}")
|
|
|
if not raw:
|
|
|
continue
|
|
|
|