Translate a video's audio using Whisper speech recognition model.
Add an MP4 file inside the /videos folder and run run_whisper_translate.py to translate from a chosen language to English and produce the output in a folder.
options:
--language Russian--task translate--model medium--device cpudefault is cuda but it requires additional steps.
more options: whisper
This repository contains a helper script that runs the Whisper CLI to translate videos and organizes the outputs.
Script: run_whisper_translate.py
Key symbols: VIDEOS_DIR, choose_video, unique_path, main
Prerequisites
- Python 3.8+ installed.
- Whisper CLI available in PATH (the script checks
shutil.which("whisper")).- Install official Whisper CLI (example):
pip install -U openai-whisperorpip install -U git+https://github.com/openai/whisper.git
- Install official Whisper CLI (example):
- If you want GPU acceleration, install PyTorch with CUDA and run on a machine with an NVIDIA GPU. The script calls Whisper with
--device cudaby default.
How it works
- Place a single
.mp4file into thevideos/folder (defined byVIDEOS_DIR), or call the script with a path to an mp4 file. - The script moves the video into
videos/<video_stem>/and runs Whisper with translation enabled. - Outputs (e.g.,
.srt,.json,.tsv) are saved into the samevideos/<video_stem>/folder.
Usage examples
-
If one
.mp4is already invideos/, run:python run_whisper_translate.py
-
To run on a specific file (absolute or relative path):
python run_whisper_translate.py /path/to/video.mp4
Default options used by the script
- Language: Russian (
--language Russian) - Task: translate (
--task translate) - Model: medium (
--model medium) - Device: cuda (
--device cuda) - Output folder:
videos/<video_stem>/(--output_dir <dest_folder>)
Customization
- To change defaults (language, model, device, etc.) edit the
cmdlist inmain. - The script handles duplicate filenames using
unique_path.
Troubleshooting
- "Error: 'whisper' CLI not found in PATH." — install Whisper CLI or add it to PATH.
- "No .mp4 files found in videos/" — put one
.mp4invideos/or pass a file path. - If multiple
.mp4files are invideos/, specify which to use or remove extras.
Output layout example
- videos/
- myvideo/
- myvideo.mp4
- myvideo.srt
- myvideo.json
- myvideo.tsv
- myvideo/
See the script source: run_whisper_translate.py