_processing_tasks_done checks task completion
This commit is contained in:
parent
41ca17acda
commit
ffe5284764
3 changed files with 22 additions and 5 deletions
|
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "whisperlivekit"
|
name = "whisperlivekit"
|
||||||
version = "0.2.13"
|
version = "0.2.13.post1"
|
||||||
description = "Real-time speech-to-text with speaker diarization using Whisper"
|
description = "Real-time speech-to-text with speaker diarization using Whisper"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = [
|
authors = [
|
||||||
|
|
@ -30,7 +30,6 @@ dependencies = [
|
||||||
"fastapi",
|
"fastapi",
|
||||||
"librosa",
|
"librosa",
|
||||||
"soundfile",
|
"soundfile",
|
||||||
"faster-whisper",
|
|
||||||
"uvicorn",
|
"uvicorn",
|
||||||
"websockets",
|
"websockets",
|
||||||
"torchaudio>=2.0.0",
|
"torchaudio>=2.0.0",
|
||||||
|
|
|
||||||
|
|
@ -464,7 +464,7 @@ class AudioProcessor:
|
||||||
yield response
|
yield response
|
||||||
self.last_response_content = response
|
self.last_response_content = response
|
||||||
|
|
||||||
if self.is_stopping and self.transcription_task and self.transcription_task.done() and self.diarization_task and self.diarization_task.done():
|
if self.is_stopping and self._processing_tasks_done():
|
||||||
logger.info("Results formatter: All upstream processors are done and in stopping state. Terminating.")
|
logger.info("Results formatter: All upstream processors are done and in stopping state. Terminating.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -517,11 +517,16 @@ class AudioProcessor:
|
||||||
|
|
||||||
async def watchdog(self, tasks_to_monitor):
|
async def watchdog(self, tasks_to_monitor):
|
||||||
"""Monitors the health of critical processing tasks."""
|
"""Monitors the health of critical processing tasks."""
|
||||||
|
tasks_remaining = [task for task in tasks_to_monitor if task]
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
if not tasks_remaining:
|
||||||
|
logger.info("Watchdog task finishing: all monitored tasks completed.")
|
||||||
|
return
|
||||||
|
|
||||||
await asyncio.sleep(10)
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
for i, task in enumerate(tasks_to_monitor):
|
for i, task in enumerate(list(tasks_remaining)):
|
||||||
if task.done():
|
if task.done():
|
||||||
exc = task.exception()
|
exc = task.exception()
|
||||||
task_name = task.get_name() if hasattr(task, 'get_name') else f"Monitored Task {i}"
|
task_name = task.get_name() if hasattr(task, 'get_name') else f"Monitored Task {i}"
|
||||||
|
|
@ -529,6 +534,7 @@ class AudioProcessor:
|
||||||
logger.error(f"{task_name} unexpectedly completed with exception: {exc}")
|
logger.error(f"{task_name} unexpectedly completed with exception: {exc}")
|
||||||
else:
|
else:
|
||||||
logger.info(f"{task_name} completed normally.")
|
logger.info(f"{task_name} completed normally.")
|
||||||
|
tasks_remaining.remove(task)
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
logger.info("Watchdog task cancelled.")
|
logger.info("Watchdog task cancelled.")
|
||||||
|
|
@ -559,6 +565,16 @@ class AudioProcessor:
|
||||||
self.diarization.close()
|
self.diarization.close()
|
||||||
logger.info("AudioProcessor cleanup complete.")
|
logger.info("AudioProcessor cleanup complete.")
|
||||||
|
|
||||||
|
def _processing_tasks_done(self):
|
||||||
|
"""Return True when all active processing tasks have completed."""
|
||||||
|
tasks_to_check = [
|
||||||
|
self.transcription_task,
|
||||||
|
self.diarization_task,
|
||||||
|
self.translation_task,
|
||||||
|
self.ffmpeg_reader_task,
|
||||||
|
]
|
||||||
|
return all(task.done() for task in tasks_to_check if task)
|
||||||
|
|
||||||
|
|
||||||
async def process_audio(self, message):
|
async def process_audio(self, message):
|
||||||
"""Process incoming audio data."""
|
"""Process incoming audio data."""
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ try:
|
||||||
HAS_MLX_WHISPER = True
|
HAS_MLX_WHISPER = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if platform.system() == "Darwin" and platform.machine() == "arm64":
|
if platform.system() == "Darwin" and platform.machine() == "arm64":
|
||||||
print(f"""{"="*50}\nMLX Whisper not found but you are on Apple Silicon. Consider installing mlx-whisper for better performance: pip install mlx-whisper\n{"="*50}""")
|
print(f"""{"="*50}\nMLX Whisper not found but you are on Apple Silicon. Consider installing mlx-whisper for better performance: pip install `mlx-whisper\n{"="*50}`""")
|
||||||
HAS_MLX_WHISPER = False
|
HAS_MLX_WHISPER = False
|
||||||
if HAS_MLX_WHISPER:
|
if HAS_MLX_WHISPER:
|
||||||
HAS_FASTER_WHISPER = False
|
HAS_FASTER_WHISPER = False
|
||||||
|
|
@ -32,6 +32,8 @@ else:
|
||||||
from faster_whisper import WhisperModel
|
from faster_whisper import WhisperModel
|
||||||
HAS_FASTER_WHISPER = True
|
HAS_FASTER_WHISPER = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
if platform.system() != "Darwin":
|
||||||
|
print(f"""{"="*50}\nFaster-Whisper not found but. Consider installing faster-whisper for better performance: pip install `faster-whisper\n{"="*50}`""")
|
||||||
HAS_FASTER_WHISPER = False
|
HAS_FASTER_WHISPER = False
|
||||||
|
|
||||||
def model_path_and_type(model_path):
|
def model_path_and_type(model_path):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue