|
| 1 | +# Gemini SRT Translator Go |
| 2 | + |
| 3 | +English | [中文](README_CN.md) |
| 4 | + |
| 5 | +Gemini SRT Translator Go - a powerful tool to translate subtitle files using Google Gemini AI. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- 🔤 **SRT Translation**: Translate `.srt` subtitle files to a wide range of languages supported by Google Gemini AI |
| 10 | +- ⏱️ **Timing & Format**: Maintains exact timestamps and basic SRT formatting of the original file |
| 11 | +- 💾 **Quick Resume**: Easily resume interrupted translations from where you left off |
| 12 | +- 🧠 **Advanced AI**: Leverages thinking and reasoning capabilities for more contextually accurate translations |
| 13 | +- 🖥️ **CLI Support**: Full command-line interface for easy automation and scripting |
| 14 | +- ⚙️ **Customizable**: Tune model parameters, adjust batch size, and access other advanced settings |
| 15 | +- 📜 **Description Support**: Add description to guide AI in using specific terminology or context |
| 16 | +- 📋 **Interactive Features**: Interactive model selection and automatic help display |
| 17 | +- 📝 **Logging**: Optional saving of progress and thinking process logs for review |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +### Prerequisites |
| 22 | + |
| 23 | +- Go 1.23 or later |
| 24 | + |
| 25 | +### Build from Source |
| 26 | + |
| 27 | +```bash |
| 28 | +git clone https://github.com/luispater/gemini-srt-translator-go.git |
| 29 | +cd gemini-srt-translator-go |
| 30 | +go mod tidy |
| 31 | +go build -o gst ./cmd |
| 32 | +``` |
| 33 | + |
| 34 | +## Configuration |
| 35 | + |
| 36 | +### Get Your API Key |
| 37 | + |
| 38 | +1. Go to [Google AI Studio](https://aistudio.google.com/apikey) |
| 39 | +2. Sign in with your Google account |
| 40 | +3. Click on **Generate API Key** |
| 41 | +4. Copy and keep your key safe |
| 42 | + |
| 43 | +### Set Your API Key |
| 44 | + |
| 45 | +Set the `GEMINI_API_KEY` environment variable with comma-separated keys for additional quota: |
| 46 | + |
| 47 | +**macOS/Linux:** |
| 48 | +```bash |
| 49 | +export GEMINI_API_KEY="your_first_api_key_here,your_second_api_key_here" |
| 50 | +``` |
| 51 | + |
| 52 | +**Windows (Command Prompt):** |
| 53 | +```bash |
| 54 | +set GEMINI_API_KEY=your_first_api_key_here,your_second_api_key_here |
| 55 | +``` |
| 56 | + |
| 57 | +**Windows (PowerShell):** |
| 58 | +```powershell |
| 59 | +$env:GEMINI_API_KEY="your_first_api_key_here,your_second_api_key_here" |
| 60 | +``` |
| 61 | + |
| 62 | +## Usage |
| 63 | + |
| 64 | +### Help and Usage |
| 65 | + |
| 66 | +```bash |
| 67 | +# Show help |
| 68 | +./gst --help |
| 69 | +# or simply run without arguments |
| 70 | +./gst |
| 71 | +``` |
| 72 | + |
| 73 | +### Command Line Interface |
| 74 | + |
| 75 | +#### Basic Translation |
| 76 | + |
| 77 | +```bash |
| 78 | +# Using environment variable (recommended) |
| 79 | +export GEMINI_API_KEY="your_api_key_here" |
| 80 | +./gst subtitle.srt -l "Simplified Chinese" |
| 81 | + |
| 82 | +# Using command line argument with multiple keys |
| 83 | +./gst subtitle.srt -l "Simplified Chinese" -k "YOUR_FIRST_API_KEY,YOUR_SECOND_API_KEY" |
| 84 | + |
| 85 | +# Set output file name |
| 86 | +./gst subtitle.srt -l "Simplified Chinese" -o translated_subtitle.srt |
| 87 | + |
| 88 | +# Interactive model selection |
| 89 | +./gst subtitle.srt -l "Brazilian Portuguese" --interactive |
| 90 | + |
| 91 | +# Resume translation from a specific line |
| 92 | +./gst subtitle.srt -l "Simplified Chinese" --start-line 20 |
| 93 | + |
| 94 | +# Suppress output |
| 95 | +./gst subtitle.srt -l "Simplified Chinese" --quiet |
| 96 | +``` |
| 97 | + |
| 98 | +#### Advanced Options |
| 99 | + |
| 100 | +```bash |
| 101 | +# Full-featured translation with custom settings |
| 102 | +./gst input.srt \ |
| 103 | + -l "Simplified Chinese" \ |
| 104 | + -k YOUR_API_KEY \ |
| 105 | + -o output_french.srt \ |
| 106 | + --model gemini-2.5-pro \ |
| 107 | + --batch-size 150 \ |
| 108 | + --temperature 0.7 \ |
| 109 | + --description "Medical TV series, use medical terminology" \ |
| 110 | + --progress-log |
| 111 | +``` |
| 112 | + |
| 113 | +#### Interactive Model Selection |
| 114 | + |
| 115 | +Use interactive mode to see and select from available models: |
| 116 | + |
| 117 | +```bash |
| 118 | +./gst subtitle.srt -l "Simplified Chinese" --interactive |
| 119 | +``` |
| 120 | + |
| 121 | +## Configuration Options |
| 122 | + |
| 123 | +### Core Parameters |
| 124 | + |
| 125 | +- `GeminiAPIKeys`: Array of Gemini API keys (parsed from comma-separated string) |
| 126 | +- `TargetLanguage`: Target language for translation |
| 127 | +- `InputFile`: Path to input SRT file |
| 128 | +- `OutputFile`: Path to output translated SRT file |
| 129 | +- `StartLine`: Line number to start translation from |
| 130 | +- `Description`: Additional instructions for translation |
| 131 | +- `BatchSize`: Number of subtitles to process in each batch |
| 132 | + |
| 133 | +### Model Parameters |
| 134 | + |
| 135 | +- `ModelName`: Gemini model to use (default: "gemini-2.5-flash") |
| 136 | +- `Temperature`: Controls randomness in output (0.0-2.0) |
| 137 | +- `TopP`: Nucleus sampling parameter (0.0-1.0) |
| 138 | +- `TopK`: Top-k sampling parameter (>=0) |
| 139 | +- `Streaming`: Enable streamed responses (default: true) |
| 140 | +- `Thinking`: Enable thinking capability (default: true) |
| 141 | +- `ThinkingBudget`: Token budget for thinking process (0-24576) |
| 142 | + |
| 143 | +### User Options |
| 144 | + |
| 145 | +- `FreeQuota`: Signal that you're using free quota (affects rate limiting) |
| 146 | +- `UseColors`: Enable colored terminal output |
| 147 | +- `ProgressLog`: Enable progress logging to file |
| 148 | +- `QuietMode`: Suppress all output |
| 149 | +- `Resume`: Automatically resume interrupted translations |
| 150 | + |
| 151 | +## Project Structure |
| 152 | + |
| 153 | +``` |
| 154 | +gemini-srt-translator-go/ |
| 155 | +├── cmd/ # Command-line interface |
| 156 | +│ └── main.go |
| 157 | +├── internal/ # Internal packages |
| 158 | +│ ├── translator/ # Core translation logic |
| 159 | +│ ├── logger/ # Logging and progress display |
| 160 | +│ └── helpers/ # Gemini API helpers |
| 161 | +├── pkg/ # Public packages |
| 162 | +│ ├── config/ # Configuration management |
| 163 | +│ ├── errors/ # Error handling |
| 164 | +│ └── srt/ # SRT parsing and formatting |
| 165 | +└── test/ # Test files |
| 166 | +``` |
| 167 | + |
| 168 | +## Main Dependencies |
| 169 | + |
| 170 | +- `github.com/spf13/cobra`: CLI framework |
| 171 | +- `google.golang.org/genai`: Official Gemini AI client |
| 172 | +- `golang.org/x/term`: Terminal password input |
| 173 | + |
| 174 | +## Testing |
| 175 | + |
| 176 | +Run the test suite: |
| 177 | + |
| 178 | +```bash |
| 179 | +go test ./... |
| 180 | +``` |
| 181 | + |
| 182 | +Run tests with coverage: |
| 183 | + |
| 184 | +```bash |
| 185 | +go test -cover ./... |
| 186 | +``` |
| 187 | + |
| 188 | +## Development |
| 189 | + |
| 190 | +### Building |
| 191 | + |
| 192 | +```bash |
| 193 | +go build -o gst ./cmd |
| 194 | +``` |
| 195 | + |
| 196 | +### Cross-compilation |
| 197 | + |
| 198 | +```bash |
| 199 | +# Windows |
| 200 | +GOOS=windows GOARCH=amd64 go build -o gst.exe ./cmd |
| 201 | + |
| 202 | +# macOS |
| 203 | +GOOS=darwin GOARCH=amd64 go build -o gst-macos ./cmd |
| 204 | + |
| 205 | +# Linux |
| 206 | +GOOS=linux GOARCH=amd64 go build -o gst-linux ./cmd |
| 207 | +``` |
| 208 | + |
| 209 | +## Features Explained |
| 210 | + |
| 211 | +### Translation Workflow |
| 212 | + |
| 213 | +1. **Input Validation**: Check files, API keys, and parameters |
| 214 | +2. **Model Validation**: Verify selected Gemini model availability |
| 215 | +3. **Token Management**: Get model token limits and validate batch sizes |
| 216 | +4. **Batch Translation**: Process subtitles in configurable batches |
| 217 | +5. **Progress Tracking**: Save progress for resumable translations |
| 218 | +6. **Output Generation**: Write translated SRT with proper formatting |
| 219 | + |
| 220 | +### Error Handling |
| 221 | + |
| 222 | +- API errors trigger key rotation when multiple keys available |
| 223 | +- File validation occurs before processing begins |
| 224 | +- Progress is saved after each successful batch |
| 225 | +- Cleanup of temporary files on completion |
| 226 | + |
| 227 | +### Multi-API Key Support |
| 228 | + |
| 229 | +- Supports rotation through multiple API keys |
| 230 | +- Automatic handling of quota limits and error recovery |
| 231 | +- Enhanced processing capability for free quota users |
| 232 | + |
| 233 | +## License |
| 234 | + |
| 235 | +Distributed under the MIT License. See the [LICENSE](LICENSE) file for details. |
| 236 | + |
| 237 | +## Contributing |
| 238 | + |
| 239 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 240 | + |
| 241 | +## Support |
| 242 | + |
| 243 | +If you encounter any issues or have questions, please check the documentation or create an issue in the repository. |
0 commit comments