百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

chatgpt-subtitle-translator

> AI 编程
开源

基于 ChatGPT 或任何与 OpenAI 兼容的 LLM 聊天完成 API 的高效翻译工具

384 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

基于 ChatGPT 或任何与 OpenAI 兼容的 LLM 聊天完成 API 的高效翻译工具

ChatGPT API SRT Subtitle Translator

Large language models (LLMs), such as ChatGPT, have demonstrated their capabilities as a robust translator, capable of handling common natural languages with contextual understanding, as well as unconventional forms of writing like word scrambling. However, it may not always produce a deterministic output or adhere to line-to-line correlation, potentially disrupting the timing of subtitles, even when instructed to follow precise instructions and with the model temperature parameter set to 0.

This utility uses the OpenAI ChatGPT API to translate text, with a specific focus on line-based translation, especially for SRT subtitles. The translator optimizes token usage by removing SRT overhead and grouping text into batches, resulting in arbitrary length translations without excessive token consumption while ensuring a one-to-one match between line input and output.

Upgrading from v2? See the v2 -> v3 Migration Guide for breaking changes.

Web Interface:

Features

  • Web User Interface (Web UI) and Command Line Interface (CLI)
  • Supports Structured Output: for more concise results, enabled by default in the Web UI and CLI
  • Supports Prompt Caching: by including the full context of translated data, the system instruction and translation context are packaged to work well with prompt caching, controlled with -c, --context (CLI only)
  • Supports any OpenAI API compatible providers such as running Ollama locally
  • Line-based batching: avoids token limit per request, reduces overhead token wastage, and maintains translation context to a certain extent
  • Optional OpenAI Moderation tool check: prevents token wastage if the model is highly likely to refuse to translate, enabled with --use-moderator (CLI only)
  • Streaming process output
  • Request per minute (RPM) rate limits
  • Progress resumption (CLI only)

Setup

Reference:

  • Node.js version >= 20 required. This README assumes bash shell environment
  • Clone this repository
    bash
    git clone https://github.com/Cerlancism/chatgpt-subtitle-translator
  • Navigate into the directory
    bash
    cd chatgpt-subtitle-translator
  • Install the requirements
    bash
    npm install
  • Give executable permission
    bash
    chmod +x cli/translator.mjs
  • Copy .example.env to .env
    bash
    cp .env.example .env
  • Add your API key to the newly created .env file

CLI

bash
cli/translator.mjs --help

Usage: translator [options]

Translation tool based on ChatGPT API

Options:

  • --from
    Source language (default: "")

  • --to
    Target language (default: "English")

  • -s, --system-instruction
    Override the prompt system instruction template Translate ${from} to ${to} with this text, ignoring --from and --to options

  • -i, --input
    Input source text with the content of this file, in .srt format or plain text

  • -o, --output
    Output file name, defaults to be based on input file name

  • -r, --structured Structured response format mode. (default: array, choices: array, object, timestamp, agent, none)

    • array Structures the input and output into an array format.
    • object Structures the input and output as a keyed object.
    • timestamp Provides the model with entry timings alongside each entry's text (a batch start offset plus per-entry offset/length in milliseconds), allowing it to merge adjacent entries into one. A batch is only retried when the output time span boundaries don't match the input - unlike other modes which retry on any line count mismatch - significantly reducing token wastage from retries. Uses more tokens per batch due to timestamps in input and output. Output entry count may differ from input, so progress file resumption is not supported.
    • agent Alias for the agent subcommand with default options. Use the dedicated subcommand for full configuration. See Agent Mode.
    • none Legacy compatibility mode, disables structured output.
  • -c, --context Include translation history up to a token budget to work well with prompt caching. Default: 2000. Set to 0 to include history without a token limit check.

    Recommended value: set `` to ~50% of the model's max context length to leave room for the current batch and system prompts. For example, for a 128K context model: --context 64000. When --batch-sizes is omitted, the batch size is derived from this budget as well.

  • -b, --batch-sizes Batch sizes of increasing order for translation prompt slices in JSON Array

    The number of lines to include in each translation prompt, provided that they are estimated to be within the token limit.
    In case of mismatched output line quantities, this number will be decreased step by step according to the values in the array, ultimately reaching one.

    Larger batch sizes generally lead to more efficient token utilization and potentially better contextual translation.
    However, mismatched output line quantities or exceeding the token limit will cause token wastage, requiring resubmission of the batch with a smaller batch size.

    When omitted, batch size is determined automatically per batch from the --context token budget: each batch is sized so that several batches of history fit in the portion of the context window freed by a trim, keeping the prompt cache warm in between. The history cost per input token is measured from the translated batches. The size is spread evenly across the remaining lines. On failure, the size is reduced and retried; once it reaches the minimum, translation falls back to single-entry mode. After a reduction, the size eases back up stepwise following consecutive successful batches.

  • -g, --guard-repetition Minimum number of pattern repeats before aborting a streaming response (default: 10). When the model falls into a repetition loop during streaming, the response is aborted and retried with a smaller batch. Set to 0 to disable repetition detection.

  • --initial-prompts Initial prompts for the translation in JSON (default: "[]")

  • --use-moderator Use the OpenAI Moderation tool

  • --moderation-model (default: "omni-moderation-latest") https://developers.openai.com/api/docs/models

  • --no-prefix-number Don't prefix lines with numerical indices. Ignored in -r, --structured array|object|timestamp - prefix numbers are always disabled there.

  • --no-line-matching Don't enforce one-to-one line quantity input output matching. Ignored in -r, --structured timestamp - line matching is always disabled there since entries may be merged.

  • -p, --plain-text Input source text with this plain text argument. Not supported in -r, --structured timestamp mode, or when using the agent subcommand with -r timestamp.

  • --no-stream Disable stream progress output to terminal (streaming is on by default)

  • --log-level
    Log level (default: debug, choices: trace, debug, info, warn, error, silent)

  • --silent
    Same as --log-level silent

  • --quiet Same as --log-level silent

Additional Options for GPT: https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create

  • -m, --model (default: "gpt-4o-mini") https://developers.openai.com/api/docs/models
  • --reasoning_effort Constrains effort on reasoning for reasoning models. Accepted values depend on the model (e.g. "low", "medium", "high"), follows the model's default when not set. "none" disables reasoning/thinking entirely (supported by OpenAI o-series/GPT-5+ and open models via Ollama such as Qwen3).
  • -t, --temperature Sampling temperature to use, should set a low value such as 0 to be more deterministic for translation (default: 0)
  • --top_p Nucleus sampling parameter, top_p probability mass
  • --presence_penalty Penalty for new tokens based on their presence in the text so far
  • --frequency_penalty Penalty for new tokens based on their frequency in the text so far
  • --logit_bias Modify the likelihood of specified tokens appearing in the completion

Agent Mode

Subcommand for multi-pass agentic translation. Accepts all standard translation options.

bash
cli/translator.mjs agent --help

Agent mode runs multiple passes before translating:

Overview - Samples the file to produce a content overview (file identity, duration, genre/tone, character names) and detects the source language.
Planning - Scans the file in token-bounded windows. Each window produces a batch summary (characters, locations, events, tone). Summaries are consolidated and used to generate a refined translation instruction.
Translation - Translates using the enriched instruction. After the first batch, a sample of the output is checked to confirm the target language before proceeding.

Structured mode defaults to array, pass --structured timestamp to use timestamp mode instead.

bash
# Default (array delegate)
cli/translator.mjs agent --input subtitles.srt --from Japanese --to English

# Timestamp delegate
cli/translator.mjs agent --input subtitles.srt --structured timestamp --from Japanese --to English
  • --no-refine
    Skip the final instruction refinement step at the end of the planning pass and use the original system instruction directly.
  • --no-fitting
    Skip LLM-based token-range fitting for planning summaries and consolidation. Summaries are used as-is regardless of token range.
  • --context-summary
    Provide a context summary directly, bypassing the planning pass entirely and proceeding straight to translation.

Examples

Plain text

bash
cli/translator.mjs --plain-text "你好"

Standard Output

Hello.

Emojis

bash
cli/translator.mjs --to "Emojis" --plain-text "Chuck Norris can walk with the animals, talk with the animals; grunt and squeak and squawk with the animals... and the animals, without fail, always say 'yessir Mr. Norris'."

Standard Output

‍‍♂️️️❗️‍==.

Scrambling

bash
cli/translator.mjs --system-instruction "Scramble characters of words while only keeping the start and end letter" --no-prefix-number --no-line-matching --plain-text "Chuck Norris can walk with the animals, talk with the animals;"

Standard Output

Cuhck Nroris can wakl wtih the aiamnls, talk wtih the aiamnls;

Unscrambling

bash
cli/translator.mjs --system-instruction "Unscramble characters back to English" --no-prefix-number --no-line-matching --plain-text "Cuhck Nroris can wakl wtih the aiamnls, talk wtih the aiamnls;"

Standard Output

Chuck Norris can walk with the animals, talk with the animals;

Plain text file

bash
cli/translator.mjs --input test/data/test_cn.txt

Input file: test/data/test_cn.txt

你好。
拜拜!

Standard Output

Hello.  
Goodbye!

SRT file

bash
cli/translator.mjs --input test/data/test_ja_small.srt

Input file: test/data/test_ja_small.srt

srt
1

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptaichatgptcligpt

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.