fix: wait for finalized wav header before transcription
This commit is contained in:
@@ -4,6 +4,7 @@ import asyncio
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
import wave
|
||||
from pathlib import Path
|
||||
|
||||
import discord
|
||||
@@ -136,8 +137,18 @@ async def wait_for_file_ready(file_path: str, attempts: int = 20, delay: float =
|
||||
if size > 0 and size == last_size:
|
||||
stable_count += 1
|
||||
if stable_count >= 2:
|
||||
logger.info("Recording file finalized: path=%s size_bytes=%s", file_path, size)
|
||||
return True
|
||||
try:
|
||||
with wave.open(file_path, "rb") as wav_file:
|
||||
wav_file.getparams()
|
||||
except (wave.Error, EOFError, OSError) as exc:
|
||||
logger.info(
|
||||
"Recording file exists and is size-stable but WAV header is not finalized yet: path=%s error=%s",
|
||||
file_path,
|
||||
exc,
|
||||
)
|
||||
else:
|
||||
logger.info("Recording file finalized: path=%s size_bytes=%s", file_path, size)
|
||||
return True
|
||||
else:
|
||||
stable_count = 0
|
||||
last_size = size
|
||||
|
||||
Reference in New Issue
Block a user