Skip to content

feat(subtitles): add on-the-fly Gemini AI subtitle translation with disk caching - #3176

Open
nutine wants to merge 3 commits into
recloudstream:masterfrom
nutine:feat/ai-subtitle-translation
Open

feat(subtitles): add on-the-fly Gemini AI subtitle translation with disk caching#3176
nutine wants to merge 3 commits into
recloudstream:masterfrom
nutine:feat/ai-subtitle-translation

Conversation

@nutine

@nutine nutine commented Sep 13, 2026

Copy link
Copy Markdown

Summary

This pull request introduces on-the-fly AI subtitle translation using the Google Gemini API with smart persistent caching:

  • Gemini Translation Engine:

    • Translates subtitle cues in batches using Google Gemini REST API.
    • Sets thinkingBudget = 0 to prevent model reasoning delay, reducing batch translation latency from ~40s to ~1s.
    • Multi-model fallback chain (gemini-3.5-flash -> gemini-2.5-flash -> gemini-2.5-flash-lite) to handle service load or quota limits.
    • Formats translated cues into standard WebVTT format.
  • Target Language Selection Dialog:

    • Dialog showing supported languages with country flag emojis.
    • In-dialog loading indicator with state guard (isAiTranslating) preventing redundant duplicate requests while in-flight.
  • Persistent Disk Caching & Dynamic Reload:

    • Saves translated .vtt files to context.filesDir/ai_subtitles/ keyed by media ID and language code.
    • Cached subtitles load instantly on subsequent visits without re-querying the API.
    • Dynamically loads and selects the generated subtitle via addAndSelectSubtitles without losing current playback position.
  • Settings Configuration:

    • Configurable Gemini API Key setting under Settings ➔ Player ➔ Subtitles with masked key display.

Test Plan

  • Unit tests (GeminiSubtitleTranslatorTest) verifying cue formatting, prompt structuring, and VTT generation (PASS).
  • Tested real .srt and .vtt file translation with live Gemini API.
  • Verified disk caching persistence and reload across player exits.
  • Verified API key configuration and validation in settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant