diff --git a/pkgs/by-name/wh/whisperx/package.nix b/pkgs/by-name/wh/whisperx/package.nix new file mode 100644 index 000000000000..c5b60fb97af6 --- /dev/null +++ b/pkgs/by-name/wh/whisperx/package.nix @@ -0,0 +1 @@ +{ python3Packages }: with python3Packages; toPythonApplication whisperx diff --git a/pkgs/development/python-modules/whisperx/default.nix b/pkgs/development/python-modules/whisperx/default.nix new file mode 100644 index 000000000000..c97e62afe913 --- /dev/null +++ b/pkgs/development/python-modules/whisperx/default.nix @@ -0,0 +1,87 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + + # build-system + setuptools, + + # dependencies + ctranslate2, + faster-whisper, + nltk, + pandas, + pyannote-audio, + torch, + torchaudio, + transformers, + + # native packages + ffmpeg, + ctranslate2-cpp, # alias for `pkgs.ctranslate2`, required due to colliding with the `ctranslate2` Python module. + + # enable GPU support + cudaSupport ? torch.cudaSupport, +}: + +let + ctranslate = ctranslate2.override { + ctranslate2-cpp = ctranslate2-cpp.override { + withCUDA = cudaSupport; + withCuDNN = cudaSupport; + }; + }; +in +buildPythonPackage rec { + pname = "whisperx"; + version = "3.3.2"; + pyproject = true; + + src = fetchFromGitHub { + owner = "m-bain"; + repo = "whisperX"; + tag = "v${version}"; + hash = "sha256-JJa8gUQjIcgJ5lug3ULGkHxkl66qnXkiUA3SwwUVpqk="; + }; + + build-system = [ setuptools ]; + + dependencies = [ + ctranslate + faster-whisper + nltk + pandas + pyannote-audio # Missing from pyproject.toml, but used in `whisperx/vad.py` + torch + torchaudio + transformers + ]; + + # As `makeWrapperArgs` does not apply to the module, and whisperx depends on `ffmpeg`, + # we replace the `"ffmpeg"` string in `subprocess.run` with the full path to the binary. + # This works for both the program and the module. + # Every update, the codebase should be checked for further instances of `ffmpeg` calls. + postPatch = '' + substituteInPlace whisperx/audio.py --replace-fail \ + '"ffmpeg"' '"${lib.getExe ffmpeg}"' + ''; + + # > Checking runtime dependencies for whisperx-3.3.2-py3-none-any.whl + # > - faster-whisper==1.1.0 not satisfied by version 1.1.1 + # This has been updated on main, so we expect this clause to be removed upon the next update. + pythonRelaxDeps = [ "faster-whisper" ]; + + pythonImportsCheck = [ "whisperx" ]; + + # No tests in repository + doCheck = false; + + meta = { + mainProgram = "whisperx"; + description = "Automatic Speech Recognition with Word-level Timestamps (& Diarization)"; + homepage = "https://github.com/m-bain/whisperX"; + changelog = "https://github.com/m-bain/whisperX/releases/tag/${src.tag}"; + license = lib.licenses.bsd2; + maintainers = [ lib.maintainers.bengsparks ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 6d1b37581114..b609c222e5a8 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -18756,6 +18756,11 @@ self: super: with self; { whispers = callPackage ../development/python-modules/whispers { }; + whisperx = callPackage ../development/python-modules/whisperx { + inherit (pkgs) ffmpeg; + ctranslate2-cpp = pkgs.ctranslate2; + }; + whitenoise = callPackage ../development/python-modules/whitenoise { }; whodap = callPackage ../development/python-modules/whodap { };