English | δΈζ
Gemini SRT Translator Go - a powerful tool to translate subtitle files using Google Gemini AI.
- π€ SRT Translation: Translate
.srtsubtitle files to a wide range of languages supported by Google Gemini AI - β±οΈ Timing & Format: Maintains exact timestamps and basic SRT formatting of the original file
- πΎ Quick Resume: Easily resume interrupted translations from where you left off
- π§ Advanced AI: Leverages thinking and reasoning capabilities for more contextually accurate translations
- π₯οΈ CLI Support: Full command-line interface for easy automation and scripting
- βοΈ Customizable: Tune model parameters, adjust batch size, and access other advanced settings
- π Description Support: Add description to guide AI in using specific terminology or context
- π Interactive Features: Interactive model selection and automatic help display
- π Logging: Optional saving of progress and thinking process logs for review
- Go 1.23 or later
git clone https://github.com/luispater/gemini-srt-translator-go.git
cd gemini-srt-translator-go
go mod tidy
go build -o gst ./cmd- Go to Google AI Studio
- Sign in with your Google account
- Click on Generate API Key
- Copy and keep your key safe
Set the GEMINI_API_KEY environment variable with comma-separated keys for additional quota:
macOS/Linux:
export GEMINI_API_KEY="your_first_api_key_here,your_second_api_key_here"Windows (Command Prompt):
set GEMINI_API_KEY=your_first_api_key_here,your_second_api_key_hereWindows (PowerShell):
$env:GEMINI_API_KEY="your_first_api_key_here,your_second_api_key_here"# Show help
./gst --help
# or simply run without arguments
./gst# Using environment variable (recommended)
export GEMINI_API_KEY="your_api_key_here"
./gst subtitle.srt -l "Simplified Chinese"
# Using command line argument with multiple keys
./gst subtitle.srt -l "Simplified Chinese" -k "YOUR_FIRST_API_KEY,YOUR_SECOND_API_KEY"
# Set output file name
./gst subtitle.srt -l "Simplified Chinese" -o translated_subtitle.srt
# Interactive model selection
./gst subtitle.srt -l "Brazilian Portuguese" --interactive
# Resume translation from a specific line
./gst subtitle.srt -l "Simplified Chinese" --start-line 20
# Suppress output
./gst subtitle.srt -l "Simplified Chinese" --quiet# Full-featured translation with custom settings
./gst input.srt \
-l "Simplified Chinese" \
-k YOUR_API_KEY \
-o output_french.srt \
--model gemini-2.5-pro \
--batch-size 150 \
--temperature 0.7 \
--description "Medical TV series, use medical terminology" \
--progress-logUse interactive mode to see and select from available models:
./gst subtitle.srt -l "Simplified Chinese" --interactiveGeminiAPIKeys: Array of Gemini API keys (parsed from comma-separated string)TargetLanguage: Target language for translationInputFile: Path to input SRT fileOutputFile: Path to output translated SRT fileStartLine: Line number to start translation fromDescription: Additional instructions for translationBatchSize: Number of subtitles to process in each batch
ModelName: Gemini model to use (default: "gemini-2.5-flash")Temperature: Controls randomness in output (0.0-2.0)TopP: Nucleus sampling parameter (0.0-1.0)TopK: Top-k sampling parameter (>=0)Streaming: Enable streamed responses (default: true)Thinking: Enable thinking capability (default: true)ThinkingBudget: Token budget for thinking process (0-24576)
FreeQuota: Signal that you're using free quota (affects rate limiting)UseColors: Enable colored terminal outputProgressLog: Enable progress logging to fileQuietMode: Suppress all outputResume: Automatically resume interrupted translations
gemini-srt-translator-go/
βββ cmd/ # Command-line interface
β βββ main.go
βββ internal/ # Internal packages
β βββ translator/ # Core translation logic
β βββ logger/ # Logging and progress display
β βββ helpers/ # Gemini API helpers
βββ pkg/ # Public packages
β βββ config/ # Configuration management
β βββ errors/ # Error handling
β βββ srt/ # SRT parsing and formatting
βββ test/ # Test files
github.com/spf13/cobra: CLI frameworkgoogle.golang.org/genai: Official Gemini AI clientgolang.org/x/term: Terminal password input
Run the test suite:
go test ./...Run tests with coverage:
go test -cover ./...go build -o gst ./cmd# Windows
GOOS=windows GOARCH=amd64 go build -o gst.exe ./cmd
# macOS
GOOS=darwin GOARCH=amd64 go build -o gst-macos ./cmd
# Linux
GOOS=linux GOARCH=amd64 go build -o gst-linux ./cmd- Input Validation: Check files, API keys, and parameters
- Model Validation: Verify selected Gemini model availability
- Token Management: Get model token limits and validate batch sizes
- Batch Translation: Process subtitles in configurable batches
- Progress Tracking: Save progress for resumable translations
- Output Generation: Write translated SRT with proper formatting
- API errors trigger key rotation when multiple keys available
- File validation occurs before processing begins
- Progress is saved after each successful batch
- Cleanup of temporary files on completion
- Supports rotation through multiple API keys
- Automatic handling of quota limits and error recovery
- Enhanced processing capability for free quota users
Distributed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please check the documentation or create an issue in the repository.