MlKitTranslationEngine

class MlKitTranslationEngine(requireWifi: Boolean = false) : TranslationEngine

ML Kit implementation of TranslationEngine. Models (about 30 MB per language) are downloaded on demand through Google Play services and kept on the device.

Parameters

requireWifi

download models on Wi-Fi only; text is sent untranslated until a model is there

Constructors

Link copied to clipboard
constructor(requireWifi: Boolean = false)

Functions

Link copied to clipboard
open suspend override fun detectLanguage(text: String): String?

Language code of text (for example fr), or null if it cannot be told.

Link copied to clipboard
open suspend override fun downloadModel(language: String)

Downloads the model for language; throws on failure.

Link copied to clipboard
open suspend override fun isModelReady(language: String): Boolean

True if the model for language is already on the device.

Link copied to clipboard
open override fun isSupported(language: String): Boolean

True if translating language to English is supported at all.

Link copied to clipboard
open suspend override fun translate(text: String, language: String): String

Translates text from language to English; the model must be ready.