1

com.google.mlkit.nl.translate.Translation.getClient 图片截图

在上图中我已经导入了 getClient() 但它再次显示我要导入

4

1 回答 1

0

我也遇到了这个问题,暂时你可以使用 Firebase 自然语言库。文件在这里

首先在你的大文件中插入这个 -

implementation 'com.google.firebase:firebase-ml-natural-language:22.0.0'
implementation 'com.google.firebase:firebase-ml-natural-language-translate-model:20.0.8'

对于翻译模型 -

val options = FirebaseTranslatorOptions.Builder()
    .setSourceLanguage(FirebaseTranslateLanguage.DE)
    .setTargetLanguage(FirebaseTranslateLanguage.TR)
    .build()
val englishGermanTranslator =  FirebaseNaturalLanguage.getInstance().getTranslator(options)


englishGermanTranslator.downloadModelIfNeeded()
    .addOnSuccessListener {
        // Model downloaded successfully. Okay to start translating.
        // (Set a flag, unhide the translation UI, etc.)
    }
    .addOnFailureListener { exception ->
        // Model couldn’t be downloaded or other internal error.
        // ...
    }
englishGermanTranslator.translate(text)
    .addOnSuccessListener { translatedText ->
        Log.d("translate","done \t $translatedText")
    }
    .addOnFailureListener { exception ->
         // Error.
         // ...
    }

希望对你有帮助

于 2020-08-12T06:50:43.757 回答