how to check TTS already support by device android? - android

I am designing an APP in Android using the TTS Engine.
As the first time, I tried to send the text to google then receive the audio from google via internet, and it is working well.
The next step is to play the TTS audio offline.
That means that I have some text, my Application will get the audio from the system, without connecting to internet.
I have implemented this:
Voice Recognition and Text to Speech
But my problem is TextToSpeech.LANG_MISSING_DATA: this is not working without internet.
If internet is not available, it is not working.
Please help me.

Check out Sifat Ifty's implementation at Text to speech(TTS)-Android
specifically the code block:
tts=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
// TODO Auto-generated method stub
if(status == TextToSpeech.SUCCESS){
int result=tts.setLanguage(Locale.US);
if(result==TextToSpeech.LANG_MISSING_DATA ||
result==TextToSpeech.LANG_NOT_SUPPORTED){
Log.e("error", "This Language is not supported");
}
else{
ConvertTextToSpeech();
}
}
else
Log.e("error", "Initilization Failed!");
}
});
This TextToSpeech.OnInitListener attempts to initialize the tts service if available. Remember to stop the tts service when you are done with it as well!

Related

How to Check if TextToSpeech Initialized With Specified Speech Engine or Not?

In Android, you create a TextToSpeech instance like this:
tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int i) {
if (i == TextToSpeech.SUCCESS) {
begin();
}
else {
Log.i(TAG, "init failed");
}
}
}, "com.google.android.tts");
Notice that the desired speech engine is specified as the last argument.
There are multiple possible speech engines that can exist on a device (Samsung, PICO, Google, and more).
Question: How can we know whether or not this this TextToSpeech instance was successful in assigning the specified Engine to itself?
I don't see any way of doing this in the documentation:
onInit() only carries SUCCESS or FAIL, and there seems to be no method to query the (private) "myEngine" variable of the TextToSpeech instance.

Russian and German support in Google's TTS

I'm trying to create an app which would use Google's TTS to read English, German and Russian texts. However currently it only speaks English. The device runs on Android 4.2.1 with Google TTS 3.10.9.
Below is the code I use for testing.
t1 = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.US);
// t1.setLanguage(Locale.GERMANY);
// t1.setLanguage(new Locale("ru"));
Log.d("TTS", "ok");
} else {
Log.d("TTS", "error");
}
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t1.speak("What is your name?", TextToSpeech.QUEUE_FLUSH, null);
// t1.speak("Wie heisst du?", TextToSpeech.QUEUE_FLUSH, null);
// t1.speak("Как Вас зовут?", TextToSpeech.QUEUE_FLUSH, null);
}
});
When I run the same code on an emulator on Android 7 I can hear all the three languages being spoken.
I couldn't find any information which would help me to answer the question: Since which version does TTS support German and Russian? The wiki page only says that the support for Russian was added in 2014. The corresponding Google Play page doesn't have any information related to versions.
When I open the TTS page on Google Play with that device I only see "Installed" button.
The solution was to turn on Wi-Fi on the device and add German and Russian in "Settings -> Language & Input -> Google voice typing -> Voices". After that the languages were downloaded and the app worked as desired.

Android Google Play Games Services Turn based Multiplayer not Automatching

I'm trying to develop a simple Turn based multiplayer game in android using Play games services. I followed all the steps in the docs: https://developers.google.com/games/services/android/turnbasedMultiplayer#implementing_auto-matching The only difference is that I don't want my players to be able to invite friends I want it to be purely Automatching. The game is only 2 player and it can only start ONCE 2 players have been matched. My problem is it doesn't seem to be automatching players. I run the app on 2 devices and they never seem to find each other... They both connect to the Play Games Services fine but they both just create a new game. Here is my code after I connect the GoogleApiClient.
#Override
public void onConnected(Bundle bundle) {
pDialog.dismiss();
Toast.makeText(this, "Connected", Toast.LENGTH_LONG).show();
showDialog("Matching players");
Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(1,1,0);
TurnBasedMatchConfig tbmc=TurnBasedMatchConfig.builder().
setAutoMatchCriteria(autoMatchCriteria).build();
Games.TurnBasedMultiplayer.createMatch(mGoogleApiClient,
tbmc).setResultCallback(new MatchInitiatedCallback(this));
}
Here is my MatchInitiatedCallback
public class MatchInitiatedCallback implements
ResultCallback<TurnBasedMultiplayer.InitiateMatchResult> {
private Context context;
public MatchInitiatedCallback(Context c) {
context = c;
}
#Override
public void onResult(TurnBasedMultiplayer.InitiateMatchResult
initiateMatchResult) {
pDialog.dismiss();
if(!initiateMatchResult.getStatus().isSuccess()) {
Toast.makeText(context, "ERROR: " +
initiateMatchResult.getStatus().getStatusCode(), Toast.LENGTH_LONG).show();
return;
}
TurnBasedMatch match = initiateMatchResult.getMatch();
if(match.getData() != null) {
Toast.makeText(context, "Player2 " + match.getData().toString(),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Player1", Toast.LENGTH_LONG).show();
initGame(match);
}
}
}
Both devices show the TOAST that says: "Player1" and call the initGame(match) method which is here:
public void initGame(TurnBasedMatch match) {
String initialise = "initialised";
Games.TurnBasedMultiplayer.takeTurn(mGoogleApiClient,
match.getMatchId(),initialise.getBytes(Charset.forName("UTF-16")),
match.getParticipantId(Games.Players.getCurrentPlayerId(mGoogleApiClient))).
setResultCallback(this);
}
#Override
public void onResult(TurnBasedMultiplayer.UpdateMatchResult
updateMatchResult) {
if(updateMatchResult.getMatch().getStatus() ==
TurnBasedMatch.MATCH_STATUS_AUTO_MATCHING) {
Toast.makeText(this, "Still automatching",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Not automatching", Toast.LENGTH_LONG).show();
}
}
And once again they both Display the TOAST: "Still automatching"
What am I doing wrong. Why don't the devices automatch. Did I skip a step somewhere. Please help.
Try to change your initGame method so it specifies null for the next participant (to let Play Game services find a player for auto-matching):
public void initGame(TurnBasedMatch match) {
String initialise = "initialised";
Games.TurnBasedMultiplayer.takeTurn(
mGoogleApiClient,
match.getMatchId(),
initialise.getBytes(Charset.forName("UTF-16")),
null
).setResultCallback(this);
}
Also make sure to use two different google+ accounts on the two devices.
I tried your code and both devices said "Player1" and "Not automatching"(!). After changing to null, first device said "Player1" and "Still automatching" and second device said "Player2 [B#41b08830"
I think your problem is due to the way invitations as well as auto matching is handled by Play Game services. When hooking up participants to a TurnBasedMultiplayer match, invitations are sent to participants one by one. When you call takeTurn in the initGame method, you must specify the next participant to receive an invitation. When that participant has accepted the invitation, he must call takeTurn and specify the next participant to receive an invitation and so on. If you specify null, it means the next invitation goes to an automatched player.

Android Text-To-Speech Configuration and Variations

I am currently developing an app that makes intensive use of Text-To-Speech (I am using android.speech.tts.TextToSpeech) I have been able to integrate TTS in my voice and at present, a default American US voice is what reads aloud my text.
I would like to know how to make configurational changes to the speech engine. For example, I would like to reduce the speed at which the text is being read, swap between male and female voices and even provide support for different languages. Can anyone please help me with this information. Thanks in Advance :)
[Below is the code I am currently using (courtesy: a very well written basic blog on android TTS), all variable have been declared I am not copying the entire code, and this code snippet works just fine.]
btnSpeak = (ImageButton) findViewById(R.id.ttsIB);
btnSpeak.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
speakOut();
}
});
#Override
public void onDestroy() {
// to shutdown TTS
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
#Override
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
{
Log.e("TTS", "This Language is not supported");
}
else
{
btnSpeak.setEnabled(true);
speakOut();
}
}
else
{
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut()
{
String text = textVal.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
I've worked with TTS a couple of years ago and remember, that there were not so much configuration possibilities.
There is a useful method setEngineByPackageName(String packageName).
Some TTS engines have separate package names for every voice. For example, with Loquendo you need to write tts.setEngineByPackageName("com.loquendo.tts.susan") and your app will speak with US voice Susan.
But some TTS engines has common application and voices as plugins. So, you can configure it only this way:
tts.setEngineByPackageName("com.svox.pico");
tts.setLanguage(Locale.US);
If there are several US voices for this engine, your application will speak with default (selected in phone preferences)

using eSpeak tts engine in application

I have this code for text to speech in my application.
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
//Setting speech language
int result = tts.setLanguage(Locale.ENGLISH);
//If your device doesn't support language you set above
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
//Cook simple toast message with message
Toast.makeText(this, "Language not supported", Toast.LENGTH_LONG).show();
//Log.e("TTS", "Language is not supported");
}
//TTS is not initialized properly
} else {
Toast.makeText(this, "TTS Initilization Failed", Toast.LENGTH_LONG).show();
//Log.e("TTS", "Initilization Failed");
}
}
My application includes many different languages like English, Hindi, Marathi, Telugu, Tamil, etc. Since the default android tts engine does not support these languages, I downloaded eSpeak tts engine from this link and installed it on my phone.
Its default language is set as English. How do i change its language in my code so that it can read unicode texts of other languages as well?
Currently, for a word in hindi script, it speaks some numbers.
How do i make it recognise the language used in the text? It shows only the locales available in the default google tts. How do I change the tts engine to eSpeak tts?
Initialize your TextToSpeech using
TextToSpeech (Context context, TextToSpeech.OnInitListener listener, String engine)
That is
tts = new TextToSpeech(this, this, "com.googlecode.eyesfree.espeak");
engine Package name of the TTS engine to use, which you can get by calling getEngines.
Try changing the Locale according to your need.
Currently it is Locale.ENGLISH change this accordingly.

Categories

Resources