Powerfull toolkit that locally transcribes, translates, and masters subtitles for your media
Project description
LeGen
LeGen is a fast, AI-powered subtitle studio that runs right on your machine. It taps into Whisper and WhisperX to transcribe speech, translates the results into the language you need, then exports polished .srt/.txt files, muxes them into MP4 containers, or even burns them straight into the video. LeGen also speaks fluent yt-dlp, pulling remote videos or playlists and embedding every subtitle track it can find before the pipeline kicks in.
This is very useful for making it available in another language, or even just subtitling any video that belongs to you or that you have the proper authorization to do so, be it a film, lecture, course, presentation, interview, etc.
Run on Colab
LeGen works on Google Colab, using their computing power to do the work. Aceess the link to run on Google Colab
Install
From PyPI (soon)
Install FFMpeg from FFMPeg Oficial Site or from your linux package manager. If using windows, prefer gyan_dev release full choco install ffmpeg-full
Install Git
Install Python Recomended version: 3.12.x. If using windows, select "Add to PATH" option when installing
Clone LeGen using git
git clone https://github.com/matheusbach/legen.git
cd legen
Install requirements using pip. Is recommended to create a virtual environment (venv) as a good practice
pip3 install -r requirements.txt --upgrade
Ensure the yt-dlp command is available in your shell so LeGen can fetch remote videos. The provided requirements install yt-dlp for convenience, and LeGen will use it to embed all subtitle tracks it can find for each item into the MP4 container.
GPU compatibility
If having troubles with GPU compatibility, get PyTorch for your GPU.
And done. Now you can use LeGen
Update
For dry-run update, use in legen folder:
git fetch && git reset --hard origin/main && git pull
pip3 install -r requirements.txt --upgrade --force-reinstall
Run locally:
To use LeGen, run the following command:
The minimum comand line is:
python3 legen.py -i [input_path]
Users could for example also translate generated subtitles for other language like portuguese (pt) adding --translate pt to the command line
Full options list are described bellow:
-
-i,--input_path: Specifies the path to the media files or a direct video/playlist URL. The CLI will download URLs withyt-dlpbefore processing. Example:LeGen -i /path/to/media/filesorLeGen -i https://www.youtube.com/watch?v=…. -
--norm: Normalizes folder times and runs vidqa on the input path before starting to process files. Useful for synchronizing timestamps across multiple media files. -
-ts:e,--transcription_engine: Specifies the transcription engine to use. Possible values are "whisperx" and "whisper". Default is "whisperx". -
-ts:m,--transcription_model: Specifies the path or name of the Whisper transcription model. A larger model will consume more resources and be slower, but with better transcription quality. Possible values: tiny, base, small, medium, large, large-v3, turbo, large-v3-turbo (default)... -
-ts:d,--transcription_device: Specifies the device to run the transcription through Whisper. Possible values: auto (default), cpu, cuda. -
-ts:c,--transcription_compute_type: Specifies the quantization for the neural network. Possible values: auto (default), int8, int8_float32, int8_float16, int8_bfloat16, int16, float16, bfloat16, float32. -
-ts:b,--transcription_batch: Specifies the number of simultaneous segments being transcribed. Higher values will speed up processing. If you have low RAM/VRAM, long duration media files or have buggy subtitles, reduce this value to avoid issues. Only works using transcription_engine whisperx. Default is 4. -
--translate: Translates subtitles to a language code if they are not the same as the original. The language code should be specified after the equals sign. For example,LeGen --translate=frwould translate the subtitles to French. -
--input_lang: Indicates (forces) the language of the voice in the input media. Default is "auto". -
-c:v,--codec_video: Specifies the target video codec. Can be used to set acceleration via GPU or another video API [codec_api], if supported (ffmpeg -encoders). Examples include h264, libx264, h264_vaapi, h264_nvenc, hevc, libx265 hevc_vaapi, hevc_nvenc, hevc_cuvid, hevc_qsv, hevc_amf. Default is h264. -
-c:a,--codec_audio: Specifies the target audio codec. Default is aac. Examples include aac, libopus, mp3, vorbis. -
-o:s,--output_softsubs: Specifies the path to the folder or output file for the video files with embedded softsub (embedded in the mp4 container and .srt files). Default is "softsubs_" followed by the input path. -
-o:h,--output_hardsubs: Specifies the output folder path for video files with burned-in captions and embedded in the mp4 container. Default is "hardsubs_" followed by the input path. -
-o:d,--output_downloads: Overrides the folder used to store media downloaded from URL inputs. Default is./downloadswhen-ireceives a URL. -
--overwrite: Overwrites existing files in output directories. By default, this option is false. -
-dl:rs,--download_remote_subs: When supplied alongside a URL input, instructsyt-dlpto download and embed every subtitle track it can find into the downloaded MP4. By default, remote subtitles are not fetched. -
--subtitle_formats: Specifies which subtitle formats should be exported. Separate multiple values with comma or space. Supported formats:srt,txt. Example:--subtitle_formats srt,txt. -
--disable_srt: Disables .srt file generation and doesn't insert subtitles in the mp4 container of output_softsubs. Equivalent to removingsrtfrom--subtitle_formats. By default, this option is false. -
--disable_softsubs: Doesn't insert subtitles in the mp4 container of output_softsubs. This option continues generating .srt files. By default, this option is false. -
--disable_hardsubs: Disables subtitle burn in output_hardsubs. By default, this option is false. -
--copy_files: Copies other (non-video) files present in the input directory to output directories. Only generates the subtitles and videos. By default, this option is false. -
--translate_engine: Selects the translation engine. Possible values:google(default),gemini. -
--gemini_api_key: Gemini API key used for translation when--translate_engine gemini. Repeat the flag or separate keys with commas/line breaks to supply multiple keys (useful for rotating free-tier quotas). Get your keys at https://aistudio.google.com/apikey
Each of these options provides control over various aspects of the video processing workflow. Make sure to refer to the documentation or help message (LeGen --help) for more details on each optionSource 0Source 2.
Downloading from URLs
When you pass a HTTP(S) URL to -i, LeGen will:
- Invoke
yt-dlpto download the target video, playlist, or batch feed. - Embed every subtitle track the platform exposes directly into the downloaded media only when
--download_remote_subsis provided. - Force
mp4output with the best available video and audio combination. - Store the media under
./downloadsor the path provided through--output_downloads. - Continue the normal transcription/translation pipeline on the freshly downloaded files with no additional steps from you.
If the value supplied to -i is neither a reachable URL nor a valid local file/folder, LeGen will abort with a clear error message so you can correct the input.
Dependencies
LeGen requires the following pip dependencies to be installed:
- deep_translator
- ffmpeg_progress_yield
- openai_whisper
- pysrt
- torch
- tqdm
- whisper
- vidqa
- whisperx-legen-fork (legen flavored fork from m-bain/whisperx)
- gemini-srt-translator
- yt-dlp
This dependencies can be installed and updated with pip install -r requirements.txt --upgrade
LeGen requires the yt-dlp CLI on your system to download remote content automatically.
You also need to install FFmpeg
Contributing
Contributions are welcome. Submit your pull request ❤️
Issues, Doubts
Not being able to use the software, or encountering an error? open an issue
Telegram Group
Welcome and don't be a sick. We are brazilian, but you can write in other language if you want. https://t.me/+c0VRonlcd9Q2YTAx
Video Tutorials
[PT-BR] [SEMI-OUTDATED] Tutorial - LeGen no Google Colab
Donations
You can donate to project using:
Monero (XMR): 86HjTCsiaELEoNhH96rTf3ezGMXgKmHjqFrNmca2tesCESdCTZvRvQ9QWQXPGDtmaZhKz4ryHCdZXFzdbmtGahVa5VMLJnx
LivePix: https://livepix.gg/legendonate
Donators
- Picasso Neves
- Erasmo de Souza Mora
- viniciuspro
- Igor
- NiNi
- PopularC
License
This project is licensed under the terms of the GNU GPLv3.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file legen-0.19.0.tar.gz.
File metadata
- Download URL: legen-0.19.0.tar.gz
- Upload date:
- Size: 51.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
284071e3ce3dc48b71fc3bbdfe54c8647b94ac0999947f64a80d556534254c3e
|
|
| MD5 |
90ad5d26a09a70fd36503483b6b057f6
|
|
| BLAKE2b-256 |
0e4affc997e0776341d84c29cbe1b0785b8e7786b400723c34a80e31cbd6579e
|
Provenance
The following attestation bundles were made for legen-0.19.0.tar.gz:
Publisher:
python-publish.yml on matheusbach/legen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
legen-0.19.0.tar.gz -
Subject digest:
284071e3ce3dc48b71fc3bbdfe54c8647b94ac0999947f64a80d556534254c3e - Sigstore transparency entry: 664320790
- Sigstore integration time:
-
Permalink:
matheusbach/legen@cd76d6487108776eea0960a58e0e11a51ab803da -
Branch / Tag:
refs/tags/v0.19.1 - Owner: https://github.com/matheusbach
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@cd76d6487108776eea0960a58e0e11a51ab803da -
Trigger Event:
release
-
Statement type:
File details
Details for the file legen-0.19.0-py3-none-any.whl.
File metadata
- Download URL: legen-0.19.0-py3-none-any.whl
- Upload date:
- Size: 45.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5f3e828e2c92b12e77fcd6578dd0ecaab9c48ad59a6b37748e2f77726293bde
|
|
| MD5 |
f9b40afe7f112919e4b921ecba61a654
|
|
| BLAKE2b-256 |
4a0bf430e09a4bc76c5ac0c2db643448cf969fb099fbd00f53d141a8a748ce8e
|
Provenance
The following attestation bundles were made for legen-0.19.0-py3-none-any.whl:
Publisher:
python-publish.yml on matheusbach/legen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
legen-0.19.0-py3-none-any.whl -
Subject digest:
b5f3e828e2c92b12e77fcd6578dd0ecaab9c48ad59a6b37748e2f77726293bde - Sigstore transparency entry: 664320810
- Sigstore integration time:
-
Permalink:
matheusbach/legen@cd76d6487108776eea0960a58e0e11a51ab803da -
Branch / Tag:
refs/tags/v0.19.1 - Owner: https://github.com/matheusbach
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@cd76d6487108776eea0960a58e0e11a51ab803da -
Trigger Event:
release
-
Statement type: