Reputation: 145
I'm working on an android Studio project, requiring text to speech. I would like to implement a program which can recognize in which language the text is written and read it with the appropriate pronunciation.
Example : if i have a text in English, i want the application to pronounce it in English with the English pronunciation.
Is it possible ?
Thank you
I have successfully implemented TTS in French and it works fine.
mTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = mTTS.setLanguage(Locale.FRENCH);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "Language not supported");
} else {
mButtonSpeak.setEnabled(true);
}
} else {
Log.e("TTS", "Initialization failed");
}
}
});
I would like to have a multilingual text to speech app
Thank you
Upvotes: 1
Views: 778
Reputation: 4381
You can identify the language of a text with Android ML Kit
Add the dependencies for the ML Kit Android libraries to your module (app-level) Gradle file (usually app/build.gradle
):
dependencies {
// ...
implementation 'com.google.firebase:firebase-ml-natural-language:20.0.0'
implementation 'com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.0'
}
To identify the language of a string, get an instance of FirebaseLanguageIdentification, and then pass the string to the identifyLanguage()
method.
For example:
FirebaseLanguageIdentification languageIdentifier =
FirebaseNaturalLanguage.getInstance().getLanguageIdentification();
languageIdentifier.identifyLanguage(text)
.addOnSuccessListener(
new OnSuccessListener<String>() {
@Override
public void onSuccess(@Nullable String languageCode) {
if (languageCode != "und") {
Log.i(TAG, "Language: " + languageCode);
} else {
Log.i(TAG, "Can't identify language.");
}
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Model couldn’t be loaded or other internal error.
// ...
}
});
Upvotes: 2