Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMS 205 - Update Master #212

Merged
merged 8 commits into from
Sep 26, 2024
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ implementation 'com.github.Explore-In-HMS.common-mobile-services:imageclassifica
```gradle
implementation 'com.github.Explore-In-HMS.common-mobile-services:account:<versionName>'
```
### Auth
###
```gradle
implementation 'com.github.Explore-In-HMS.common-mobile-services:auth:<versionName>'
implementation 'com.github.Explore-In-HMS.common-mobile-services::<versionName>'
```
### Safety
```gradle
Expand Down Expand Up @@ -1201,7 +1201,7 @@ imageClassification.analyseImage(bitmap){ classificationResult ->
## Account
This library provides AccountService interface to handle Google Account Service and Huawei Account Kit with a single code base.

Note: To enable Firebase Authentication, activate the Google sign-in method, add your Android app details (app name, package name, and SHA-1 fingerprint), and place the `google-services.json` file in your app directory; similarly, for HMS Account Kit, enter your SHA-256 fingerprint in the AppGallery Connect Project Settings, enable Account Kit, and place the downloaded `agconnect-services.json` file in the same directory.
Note: To enable Firebase entication, activate the Google sign-in method, add your Android app details (app name, package name, and SHA-1 fingerprint), and place the `google-services.json` file in your app directory; similarly, for HMS Account Kit, enter your SHA-256 fingerprint in the AppGallery Connect Project Settings, enable Account Kit, and place the downloaded `agconnect-services.json` file in the same directory.

### How to use

Expand Down Expand Up @@ -1251,6 +1251,8 @@ accountService.signOut()
## Auth
This library provides AuthService interface to handle Firebase Auth Service and AGC Auth Service with single code base.

**Note**: In both Firebase (GMS) and the Auth Service (HMS), each authentication method (such as `phone`, `email`, `Google`, `Mobile number`, `Email address`, `HUAWEI ID`) is disabled by default. To use them, you need to go to the respective Console and navigate to the **Authentication** section. In Firebase (GMS), under the **Sign-in method** tab, you can enable each provider, and in the Auth Service (HMS), under the **Authentication mode** tab, you can enable the required options. Without this step, these authentication methods won't be available in your app.

### How to use

First, initialize `AuthService`:
Expand Down
2 changes: 1 addition & 1 deletion texttospeech/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply from: "$project.rootDir/base_sdk.gradle"

dependencies {
implementation 'com.huawei.hms:ml-computer-voice-tts:3.7.0.303'
implementation 'com.huawei.hms:ml-computer-voice-tts:3.12.0.301'
api project(":core")
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Translator {
*/
fun getClient(
context: Context,
apiKey: String? = null
): ITranslator {
return when (Device.getMobileServiceType(context)) {
MobileServiceType.GMS -> {
Expand All @@ -43,9 +44,14 @@ class Translator {
translatorFactory.create()
}
MobileServiceType.HMS -> {
val translatorFactory =
TranslatorFactory.createFactory<HuaweiTranslator>()
translatorFactory.create()
val translatorFactory = TranslatorFactory.createFactory<HuaweiTranslator>()
val translator = translatorFactory.create()
if (translator is HuaweiTranslator) {
apiKey?.let {
translator.setApiKey(it)
} ?: throw IllegalArgumentException("API key is required for HuaweiTranslator")
}
translator
}
MobileServiceType.NON -> throw IllegalArgumentException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.hms.lib.commonmobileservices.translate.common.DeleteModelResult
import com.hms.lib.commonmobileservices.translate.common.DownloadModelResult
import com.hms.lib.commonmobileservices.translate.common.RequiresModelDownloadResult
import com.hms.lib.commonmobileservices.translate.common.TranslateResult
import com.huawei.hms.mlsdk.common.MLApplication
import com.huawei.hms.mlsdk.model.download.MLLocalModelManager
import com.huawei.hms.mlsdk.model.download.MLModelDownloadListener
import com.huawei.hms.mlsdk.model.download.MLModelDownloadStrategy
Expand All @@ -33,6 +34,25 @@ class HuaweiTranslator : ITranslator {
private val modelManager = MLLocalModelManager.getInstance()
private lateinit var translator: MLLocalTranslator

/**
* Sets the API key for the ML Kit application instance.
*
* This function sets the provided API key to the ML Kit instance. If the
* API key is blank or empty, an exception is thrown to indicate that the
* API key must be set before initialization.
*
* @param apiKey The API key to be used for ML Kit services.
*
* @throws Exception If the provided API key is blank or not set.
*/
fun setApiKey(apiKey: String) {
if (apiKey.isBlank()) {
throw Exception("API key not set. Set api key before initialization.")
} else {
MLApplication.getInstance().apiKey = apiKey
}
}

/**
* Translates the given text from the source language to the target language.
*
Expand Down
Loading