Generation of captions fail because of wrong NumPy version

I’m not actually sure if it was after a Peertube upgrade, or my recent upgrade of Python (because the Youtube import required it), but at some point the generation of captions started failing because of a wrong NumPy version.

How can I fix that?

Video-transcription log:

ExecaError: Command was killed with SIGSEGV (Segmentation fault): /var/www/peertube/storage/bin/pip/bin/whisper-ctranslate2 /var/www/peertube/storage/streaming-playlists/hls/4f0290fd-f7bb-4eac-81f9-8c3f8f2726d8/a199c79c-e6d6-40b6-9ccc-50f4e2f6b80d-1080-fragmented.mp4 --model small --word_timestamps True --vad_filter true --vad_min_silence_duration_ms 5000 --output_format all --output_dir /var/www/peertube/storage/tmp/transcription/cqMrAkKA7YZPJHaUifopcn


A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Would greatly appreciate some help with this.

Hi,

Try to remove /var/www/peertube/storage/bin/pip/bin/whisper-ctranslate2 and restart peertube

I tried to delete whisper-ctranslate2, and also all files and folders connected to the Python error message. Everything seems to be reinstalled after the restart (or when I try to run a create caption on a video) but I still get the same error:

ExecaError: Command was killed with SIGSEGV (Segmentation fault): /var/www/peertube/storage/bin/pip/bin/whisper-ctranslate2 /var/www/peertube/storage/streaming-playlists/hls/ed6430a6-34e0-4585-bd7a-252c85289a2a/1851ea2b-83fc-4070-b90b-ad78c2180d4d-1080-fragmented.mp4 --model small --word_timestamps True --vad_filter true --vad_min_silence_duration_ms 5000 --output_format all --output_dir /var/www/peertube/storage/tmp/transcription/iSAQhLxdqaFyvJfe1PYXRe


A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/var/www/peertube/storage/bin/pip/bin/whisper-ctranslate2", line 8, in <module>
    sys.exit(main())
  File "/var/www/peertube/storage/bin/pip/src/whisper_ctranslate2/whisper_ctranslate2.py", line 232, in main
    result = transcribe.inference(
  File "/var/www/peertube/storage/bin/pip/src/whisper_ctranslate2/transcribe.py", line 131, in inference
    segments, info = self.model.transcribe(
  File "/var/www/peertube/storage/bin/pip/faster_whisper/transcribe.py", line 848, in transcribe
    speech_chunks = get_speech_timestamps(audio, vad_parameters)
  File "/var/www/peertube/storage/bin/pip/faster_whisper/vad.py", line 84, in get_speech_timestamps
    model = get_vad_model()
  File "/var/www/peertube/storage/bin/pip/faster_whisper/vad.py", line 252, in get_vad_model
    return SileroVADModel(encoder_path, decoder_path)
  File "/var/www/peertube/storage/bin/pip/faster_whisper/vad.py", line 258, in __init__
    import onnxruntime
  File "/var/www/peertube/storage/bin/pip/onnxruntime/__init__.py", line 23, in <module>
    from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
  File "/var/www/peertube/storage/bin/pip/onnxruntime/capi/_pybind_state.py", line 32, in <module>
    from .onnxruntime_pybind11_state import *  # noqa
AttributeError: _ARRAY_API not found
ImportError: numpy.core.multiarray failed to import

The above exception was the direct cause of the following exception:

SystemError: <built-in function __import__> returned a result with an error set
    at getFinalError (file:///var/www/peertube/versions/peertube-v7.0.1/node_modules/execa/lib/return/final-error.js:6:9)
    at makeError (file:///var/www/peertube/versions/peertube-v7.0.1/node_modules/execa/lib/return/result.js:108:16)
    at getAsyncResult (file:///var/www/peertube/versions/peertube-v7.0.1/node_modules/execa/lib/methods/main-async.js:167:4)
    at handlePromise (file:///var/www/peertube/versions/peertube-v7.0.1/node_modules/execa/lib/methods/main-async.js:150:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Ctranslate2Transcriber.transcribe (file:///var/www/peertube/versions/peertube-v7.0.1/packages/transcription/dist/whisper/transcriber/ctranslate2-transcriber.js:18:9)
    at async file:///var/www/peertube/versions/peertube-v7.0.1/dist/core/lib/video-captions.js:83:36
    at async VideoPathManager.makeAvailableFactory (file:///var/www/peertube/versions/peertube-v7.0.1/dist/core/lib/video-path-manager.js:166:22)
    at async generateSubtitle (file:///var/www/peertube/versions/peertube-v7.0.1/dist/core/lib/video-captions.js:80:9)
    at async Object.wrapPromiseFun (file:///var/www/peertube/versions/peertube-v7.0.1/dist/core/lib/plugins/hooks.js:8:24)
    at async /var/www/peertube/versions/peertube-v7.0.1/node_modules/bullmq/dist/cjs/classes/worker.js:512:32
    at async Worker.retryIfFailed (/var/www/peertube/versions/peertube-v7.0.1/node_modules/bullmq/dist/cjs/classes/worker.js:741:24)

Thanks, try to update packages/transcription/dist/whisper/engines.js file (in your peertube-latest directory) by replacing whisper ctranslate version from 0.4.4 to 0.5.2, remove the binary and restart peertube to see if it fixes your issue

Thanks, but I still get the same error message. Very strange. I deleted everything Python that seems to be related to this, and it looks like the correct version of whisper ctranslate is installed, but still.

Try PYTHONPATH=/var/www/peertube/storage/bin/pip pip3 cache purge, then rm -r /var/www/peertube/storage/bin/pip, restart peertube and retry?

(the warning won’t disappear but it may fix the issue with 0.5.2 version)

That worked! Thanks for all your help :grinning: