whisper_launcher.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. """
  3. whisper_launcher.py — WhisperLiveKit startup wrapper
  4. Applies two compatibility fixes before importing WhisperLiveKit:
  5. 1. FFmpeg path — adds imageio-ffmpeg's bundled binary to PATH so
  6. WhisperLiveKit's ffmpeg_manager can find ffmpeg without a system
  7. install. If imageio-ffmpeg is absent it falls back to the system PATH.
  8. 2. torchaudio shim — diart/audio.py calls torchaudio.set_audio_backend()
  9. at import time, which was removed in torchaudio 2.x. We inject a no-op
  10. before WhisperLiveKit (and therefore diart) is imported.
  11. """
  12. import os
  13. import sys
  14. # ── Fix 1: make ffmpeg available via imageio-ffmpeg bundled binary ────────────
  15. try:
  16. import imageio_ffmpeg # type: ignore
  17. _ffmpeg_exe = imageio_ffmpeg.get_ffmpeg_exe()
  18. _ffmpeg_dir = os.path.dirname(_ffmpeg_exe)
  19. os.environ["PATH"] = _ffmpeg_dir + os.pathsep + os.environ.get("PATH", "")
  20. print(f"[Launcher] ffmpeg: {_ffmpeg_exe}")
  21. except ImportError:
  22. print("[Launcher] WARNING: imageio-ffmpeg not installed — system ffmpeg must be in PATH.")
  23. print("[Launcher] Run: pip install imageio-ffmpeg")
  24. except Exception as exc:
  25. print(f"[Launcher] WARNING: could not locate imageio-ffmpeg binary: {exc}")
  26. # ── Fix 2: diart torchaudio compatibility shim ────────────────────────────────
  27. try:
  28. import torchaudio # type: ignore
  29. if not hasattr(torchaudio, "set_audio_backend"):
  30. torchaudio.set_audio_backend = lambda backend: None
  31. print("[Launcher] Patched torchaudio.set_audio_backend (diart compatibility)")
  32. except ImportError:
  33. pass # torchaudio not present; WhisperLiveKit will report the error itself
  34. # ── Start WhisperLiveKit ──────────────────────────────────────────────────────
  35. from whisperlivekit.cli import main # type: ignore
  36. sys.exit(main())