refactor(tools): fold sniff/read into one with-block, lifecycle timing locals
This commit is contained in:
@@ -335,10 +335,9 @@ def _sniff_audio_container(path: str) -> str:
|
||||
from tools.audio_container import sniff_container
|
||||
try:
|
||||
with open(path, "rb") as fh:
|
||||
head = fh.read(12)
|
||||
return sniff_container(fh.read(12)) or "unknown"
|
||||
except OSError:
|
||||
return "unknown"
|
||||
return sniff_container(head) or "unknown"
|
||||
|
||||
|
||||
def _repair_ogg_container(file_str: str) -> str:
|
||||
@@ -351,7 +350,7 @@ def _repair_ogg_container(file_str: str) -> str:
|
||||
repaired = _ffmpeg_transcode_to_opus(file_str, file_str)
|
||||
if repaired:
|
||||
return repaired
|
||||
honest = file_str[:-4] + "." + container
|
||||
honest = f"{file_str[:-4]}.{container}"
|
||||
try:
|
||||
os.replace(file_str, honest)
|
||||
except OSError:
|
||||
|
||||
@@ -89,8 +89,7 @@ def warm_tts_provider(tts_config: Optional[Dict[str, Any]] = None, provider: Opt
|
||||
warmer = _local_tts_warmers().get(name)
|
||||
if warmer is not None:
|
||||
cache = _LOCAL_TTS_MODEL_CACHES.get(name, {})
|
||||
before = len(cache)
|
||||
started = time.monotonic()
|
||||
before, started = len(cache), time.monotonic()
|
||||
try:
|
||||
warmer(tts_config)
|
||||
except Exception as exc: # engine missing, download failed, bad voice…
|
||||
|
||||
@@ -183,8 +183,8 @@ class _StreamerPlayback:
|
||||
self._prefetch_sem.acquire()
|
||||
chunk_queue: "queue.Queue[Optional[bytes]]" = queue.Queue(maxsize=self._CHUNK_QUEUE_MAX)
|
||||
self._audio_queue.put(chunk_queue)
|
||||
self._prefetch_threads.append(
|
||||
threading.Thread(target=self._consume_to_queue, args=(audio_iter, chunk_queue), daemon=True))
|
||||
self._prefetch_threads.append(threading.Thread(
|
||||
target=self._consume_to_queue, args=(audio_iter, chunk_queue), daemon=True))
|
||||
self._prefetch_threads[-1].start()
|
||||
|
||||
def _consume_to_queue(self, audio_iter: Iterator[bytes], chunk_queue: "queue.Queue[Optional[bytes]]") -> None:
|
||||
|
||||
Reference in New Issue
Block a user