1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 setuptools,
8
9 # dependencies
10 ctranslate2,
11 faster-whisper,
12 nltk,
13 pandas,
14 pyannote-audio,
15 torch,
16 torchaudio,
17 transformers,
18
19 # native packages
20 ffmpeg,
21 ctranslate2-cpp, # alias for `pkgs.ctranslate2`, required due to colliding with the `ctranslate2` Python module.
22
23 # enable GPU support
24 cudaSupport ? torch.cudaSupport,
25}:
26
27let
28 ctranslate = ctranslate2.override {
29 ctranslate2-cpp = ctranslate2-cpp.override {
30 withCUDA = cudaSupport;
31 withCuDNN = cudaSupport;
32 };
33 };
34in
35buildPythonPackage rec {
36 pname = "whisperx";
37 version = "3.3.2";
38 pyproject = true;
39
40 src = fetchFromGitHub {
41 owner = "m-bain";
42 repo = "whisperX";
43 tag = "v${version}";
44 hash = "sha256-JJa8gUQjIcgJ5lug3ULGkHxkl66qnXkiUA3SwwUVpqk=";
45 };
46
47 build-system = [ setuptools ];
48
49 dependencies = [
50 ctranslate
51 faster-whisper
52 nltk
53 pandas
54 pyannote-audio # Missing from pyproject.toml, but used in `whisperx/vad.py`
55 torch
56 torchaudio
57 transformers
58 ];
59
60 # As `makeWrapperArgs` does not apply to the module, and whisperx depends on `ffmpeg`,
61 # we replace the `"ffmpeg"` string in `subprocess.run` with the full path to the binary.
62 # This works for both the program and the module.
63 # Every update, the codebase should be checked for further instances of `ffmpeg` calls.
64 postPatch = ''
65 substituteInPlace whisperx/audio.py --replace-fail \
66 '"ffmpeg"' '"${lib.getExe ffmpeg}"'
67 '';
68
69 # > Checking runtime dependencies for whisperx-3.3.2-py3-none-any.whl
70 # > - faster-whisper==1.1.0 not satisfied by version 1.1.1
71 # This has been updated on main, so we expect this clause to be removed upon the next update.
72 pythonRelaxDeps = [ "faster-whisper" ];
73
74 pythonImportsCheck = [ "whisperx" ];
75
76 # No tests in repository
77 doCheck = false;
78
79 meta = {
80 mainProgram = "whisperx";
81 description = "Automatic Speech Recognition with Word-level Timestamps (& Diarization)";
82 homepage = "https://github.com/m-bain/whisperX";
83 changelog = "https://github.com/m-bain/whisperX/releases/tag/${src.tag}";
84 license = lib.licenses.bsd2;
85 maintainers = [ lib.maintainers.bengsparks ];
86 };
87}