• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Subtitle translator

srt-GPT-translator

En | 中文说明

This tool is designed to help users translate srt file into a different language using the OpenAI API (model="gpt-3.5-turbo"). Support bilingual subtitles output.

Features

  • Each translation consists of multiple subtitle blocks, not exceeding 1024 characters, to maintain smooth context.
  • Introduced a mechanism to check the OpenAI API translation results. If the format does not correspond to the original text, it will be re-translated. If the translation is still incorrect after three attempts, the original short text for that section will be returned.

Installation

To use this tool, you will need to have Python 3 installed on your system, as well as the following packages:

You can install these packages by running the following command:

pip install -r requirements.txt

git clone

git clone https://github.com/jesselau76/srt-gpt-translator.git

Update to new version

cd srt-gpt-translator
git pull
pip install -r requirements.txt

Usage

To use this tool, you need rename settings.cfg.example to settings.cfg at first.

cd srt-gpt-translator
mv settings.cfg.example settings.cfg
nano settings.cfg
openai-apikey = sk-xxxxxxx

replace sk-xxxxxxx to your OpenAI api key. Change others options then press CTRL-X to save.

run the command:

python3 srt_translation.py [-h] [--test] filename

positional arguments:
  filename    Name of the input file

options:
  -h, --help  show this help message and exit
  --test      Only translate the first 3 short texts

Simply run the srt_translation.py script with the file you want to translate or convert as an argument. For example, to translate a srt file named example.srt, you would run the following command:

python3 srt_translation.py example.srt

By default, the script will attempt to translate the text into the language specified in the settings.cfg file under the target-language option.

Feature

  • The code reads the OpenAI API key, target language, and other options from a settings.cfg file.
  • The code provides a progress bar to show the progress of srt translation
  • Test function available. Only translate 3 short texts to save your API usage with --test.

Configuration

The settings.cfg file contains several options that can be used to configure the behavior of the script:

  • openai-apikey: Your API key for the OpenAI API.
  • target-language: The language you want to translate the text into (e.g. "English", "Chinese", "Japanese").

Output

The output of the script will be two files:

  • An SRT file with the same name as the input file, but with _translated added to the end. For example, if the input file is example.srt, the output file will be example_translated.srt.
  • Another bilingual subtitle file, an SRT file with the same name as the input file, but _translated_bilingual is added at the end. For example, if the input file is example.srt, the output file will be example_translated_bilingual.srt.

License

This tool is released under the MIT License.

Disclaimer:

The SRT Translator tool is provided for educational and informational purposes only. The accuracy, reliability, and completeness of the translations generated by the OpenAI API model ("gpt-3.5-turbo") used in this tool cannot be guaranteed. Users of the SRT Translator tool are solely responsible for verifying the accuracy and usefulness of the translations obtained, and should not rely solely on them without further verification. The use of the SRT Translator tool is at the user's own risk, and the tool's developers and contributors shall not be liable for any damages or losses arising from its use. By using the SRT Translator tool, you agree to these terms and conditions.

If you have any concerns or suggestions about the use of this project, please contact us through the issues section.