External content and AI services
Metrolist uses external services to add lyrics and language features to music metadata. Lyrics translation accepts a user-selected provider, sends non-empty lyric lines to that provider, and returns results to the lyric view while keeping the original line structure.
Service roles
The service layer separates general AI translation from dedicated translation. AI providers use a chat-style interface for translation, romanization, and transcription. DeepL provides a separate translation path with its own language and formality rules. This keeps provider choice independent from the lyric screen that displays the result. (app/…/OpenRouterService.kt• L33-112, app/…/DeepLService.kt• L18-33)
| Service role | User value | Result shape |
|---|---|---|
| AI provider | Translates lyrics or changes their written form | One output line for each input line |
| DeepL provider | Provides dedicated language translation | One output line for each input line |
| Custom endpoint | Lets the user use a compatible chat service | The same line-based translation result |
AI provider choices
The settings page presents several hosted AI services and a custom endpoint option. The selected provider supplies the endpoint and model context, while the API client uses a shared chat request shape for the providers that support it. (app/…/AiSettings.kt• L77-103)
References: app/…/AiSettings.kt• L77-103 app/…/OpenRouterService.kt• L43-77
Dedicated translation service
DeepL is handled as a separate service because it does not use the AI chat flow. The client sends each lyric line as a separate text item and preserves formatting. Its formality choice changes the tone of the result where the target language supports it. (app/…/DeepLService.kt• L26-72)
References: app/…/DeepLService.kt• L18-72 app/…/AiSettings.kt• L532-565
Translation flow
The translation flow connects the lyric view, provider settings, external service, and local lyric record. It filters blank lines before the request and maps returned lines back to the original lyric positions so display timing and layout remain tied to the source lyrics. (app/…/LyricsTranslationHelper.kt• L168-218)
This diagram shows how a user request becomes visible and saved lyric translations.
flowchart LR
A[Lyrics view] --> B[Translation helper]
B --> C{Selected service}
C -->|AI provider| D[Chat translation client]
C -->|DeepL| E[Dedicated translation client]
D --> F[Line-based result]
E --> F
F --> G[Update lyric lines]
F --> H[Save translation with language and mode]
Translation modes
AI translation supports two user-facing modes. Literal mode translates meaning and aims to keep the lyric flow. Transcribed mode represents pronunciation in the target script instead of translating meaning. The target language applies to both the request and the saved result. (app/…/AiSettings.kt• L249-280, app/…/OpenRouterService.kt• L136-197)
References: app/…/AiSettings.kt• L312-343 app/…/OpenRouterService.kt• L136-197
Lyric result persistence
A completed translation is held in the lyric view for immediate display and may be saved with the song. The saved record includes the target language and mode. The view loads a saved result only when those values match the current request, which prevents an old translation from appearing under a new setting. (app/…/LyricsTranslationHelper.kt• L129-165, app/…/LyricsEntity.kt• L12-23)
References: app/…/LyricsTranslationHelper.kt• L129-165 app/…/LyricsTranslationHelper.kt• L368-423 app/…/LyricsEntity.kt• L12-23
Streaming behavior
Streaming lets supported AI services return translation text while the request is still running. The app accumulates the incoming event data, shows partial lines when it can identify them, and performs a final line parse before it marks the translation complete. (app/…/OpenRouterStreamingService.kt• L37-122, app/…/LyricsTranslationHelper.kt• L287-346)
The stream has three meaningful outcomes:
Contentupdates the visible partial translation.Completecarries the parsed line list.Errorstops the flow and exposes an error state.
The non-streaming path remains available for custom services or when streaming is disabled. DeepL always uses its direct request path. (app/…/LyricsTranslationHelper.kt• L277-359)
References: app/…/OpenRouterStreamingService.kt• L75-135 app/…/LyricsTranslationHelper.kt• L277-359
Configuration boundaries
The settings screen stores provider choice, credentials, endpoint, model, target language, translation mode, and optional prompt text as user preferences. Provider selection changes which credential and request path are used. DeepL uses its own key and formality setting. (app/…/AiSettings.kt• L64-75, app/…/PreferenceKeys.kt• L445-467)
| Setting group | Purpose | Applies to |
|---|---|---|
| Provider and API key | Selects the service and authorizes requests | AI or DeepL flow |
| Endpoint and model | Selects the chat destination and model | AI flow |
| Target language | Sets the output language or script | Both flows |
| Translation mode | Selects meaning translation or pronunciation transcription | AI flow |
| System prompt | Adjusts the AI instruction while keeping the line contract | AI flow |
| DeepL formality | Sets the supported writing tone | DeepL flow |
Request contract
The AI request asks for a structured object whose lines array matches the input line count. The response parser accepts the structured form and pads or trims results to protect the line-by-line mapping used by the lyric view. (app/…/OpenRouterService.kt• L114-134, app/…/OpenRouterService.kt• L287-322)
References: app/…/OpenRouterService.kt• L114-134 app/…/OpenRouterService.kt• L287-322 app/…/DeepLService.kt• L106-123
User feature integration
The lyric screens start translation only when lyrics are visible and the selected service has a key. They observe shared translation status, cancel work when the screen leaves composition, and clear displayed results when the user removes translations. (app/…/OriginalLyrics.kt• L362-421, app/…/ExperimentalLyrics.kt• L232-295)
This design keeps external requests tied to a visible user feature rather than to general catalog loading. A failed request changes the translation status and leaves the original lyrics available. (app/…/LyricsTranslationHelper.kt• L424-448)
References: app/…/OriginalLyrics.kt• L362-421 app/…/ExperimentalLyrics.kt• L232-295 app/…/LyricsTranslationHelper.kt• L424-448
Change checklist
When these files or sections are changed, remember to consider these:
- Keep provider names and endpoint choices aligned between
AiSettingsand the request routing inLyricsTranslationHelper. - Keep the
linesresponse contract aligned across normal requests, streaming events, and the DeepL result mapper. - Keep
translationLanguageandtranslationModechecks aligned with the settings passed into the lyric views. - Keep the lyric database schema aligned with the saved translation metadata so cached results cannot match the wrong request.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Required service key is blank | No external request starts and the user sees a key error | The lyric flow checks the effective provider key before translation |
| Provider returns malformed or incomplete line data | Some lines can be missing or misaligned | Structured parsing trims or pads the result to the expected count |
| Streaming endpoint emits an error or ends without a result | Partial text is not saved as a completed translation | The stream emits Error unless final parsing succeeds |
| Saved language or mode differs from current settings | A stale translation must not be shown | Database loading requires both metadata values to match |
| Lyric screen leaves composition during a request | A late result could update an inactive screen | The helper cancels the job and checks composition state |
Key files
| File | Why to read it |
|---|---|
| app/…/LyricsTranslationHelper.kt | Main coordinator for provider selection, caching, UI state, persistence, and error handling |
| app/…/OpenRouterService.kt | Defines the AI request and response contract for non-streaming work |
| app/…/OpenRouterStreamingService.kt | Defines progressive AI response handling |
| app/…/DeepLService.kt | Defines the dedicated translation path |
| app/…/AiSettings.kt | Shows the user-facing provider and translation configuration |
| app/…/LyricsEntity.kt | Defines the saved lyric translation fields |
| app/…/OriginalLyrics.kt | Shows how translation connects to the main lyric feature |
| app/…/ExperimentalLyrics.kt | Shows the same service contract in the alternate lyric experience |