I have referred speak-with-tts-such-as-hindi
and i have done like this:
extToSpeech text2speechHi;
text2speechHi=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
text2speechHi.setLanguage(new Locale("hin"));
}
}
});
text2speechHi.speak(getResources().getString(R.string.hindi_text), TextToSpeech.QUEUE_FLUSH, null);
But still not reading....
how to see the output ? whether change any device setting in which i run the code?? or need to install anything??
what is this eSpeak they have mention in that link...any other free option available?? Any one who implemented this successfully????
It is working in fine for English text2speech.setLanguage(Locale.UK);
You are calling speak() before initialization is done, i.e., before onInit is called, consequently setLanguage hasn't been called yet. Refactor your code to follow the asynchronous pattern, by e.g. moving speak() into the onInit method.
EDIT: OP says code snippet in question is not representative of the actual code. Awaiting clarification before removing or updating answer.
Related
I am trying to implement Text-to-speech in my android auto app but unable to hear it on Desktop head unit. I have also tried it on Car Head unit but no luck.
below is the code i am using
TextToSpeech tts=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
and on button click i am using
tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
also tried to turn OFF Bluetooth Headset as suggested in xda forums
but still same issue.
Do i need to add any extra library like "gear.aar" to make it work for Auto as the code is in CarActivity
speak() method requires four parameters to execute the job
I solved this using below code
tts.speak(readText, TextToSpeech.QUEUE_ADD, null, ""+Calendar.getInstance().getTimeInMillis());
I had the same problem.
This is what should be done:
be sure you call tts.speak(...) after TTS is initialized (return 0 - SUCCESS)
turn off bluetooth on the computer
This is my second question here. I am not 100% on the formatting and etiquette yet. I apologize in advance. I have a published app using the BaseGameUtils provided by Google. My achievements unlock properly, and the popups show properly, using incrementImmediate(parameters) with a result. However, the result, which I do receive, always comes back as STATUS_OK, even when the call results in unlocking the achievement. I can't manage to get result.getStatus().getStatusCode() to ever be STATUS_ACHIEVEMENT_UNLOCKED. Can anyone help?
Try to use the code given in this SO question, it will make your achievement increment by the amount of steps you want.
Games.Achievements.incrementImmediate(GoogleApiClient apiClient, String id, int numSteps).setResultCallback(new ResultCallback<Achievements.UpdateAchievementResult>() {
#Override
public void onResult(UpdateAchievementResult result) {
if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED) {
}
}
});
The STATUS_ACHIEVEMENT_UNLOCKED indicates that the incremental achievement was also unlocked when the call was made to increment the achievement.
You can also try to check this related SO question.
I have an application that according to some events, changes a normal notification to text-to-speech in order to since sometimes the phone isn't available to users, and it'll be safer not to handle the phone.
For example, when you're driving, this is dangerous, so i want to turn the notifications to text-to-speech.
I've looked for a long time some explanation for turning text-to-speech when driving, but i can't find any reference for that no where i search.
For generating text-to-speech, i have this part, which works fine :
private TextToSpeech mTextToSpeech;
public void sayText(Context context, final String message) {
mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
try {
if (mTextToSpeech != null && status == TextToSpeech.SUCCESS) {
mTextToSpeech.setLanguage(Locale.US);
mTextToSpeech.speak(message, TextToSpeech.QUEUE_ADD, null);
}
} catch (Exception ex) {
System.out.print("Error handling TextToSpeech GCM notification " + ex.getMessage());
}
}
});
}
But, i don't know how to check if i'm currently driving or not.
As Ashwin suggested, you can use Activity recognition Api, but there's a downside of that, the driving samples you'll receive, has a field of 'confidence' which isn't always accurate, so you'll have to do extra work(such as check locations to see if you actually moved) in order to fully know if the user moved.
You can use google's FenceApi which allows you to define a fence of actions such as driving, walking, running, etc. This api launched recently. If you want a sample for using it, you can use this answer.
You can pull this git project (everything free), which does exactly what you want : adds to the normal notification a text-to-speech when you're driving.
In order to know whether you are driving or not you can use Activity Recognition API
Here is a great tutorial that might help you out Tutorial and Source Code
I have an HD Desire phone with android 2.3.
The TTS is working fine and it speaks every text I give. But when I use this either of the lines below to set my own voice for some texts, it simply ignores it and synthesizes the text, just like the line is not written!
tts.addSpeech("salam", "/sdcard/salam.wav");
tts.addSpeech("shalam", "com.company.appname", R.raw.shalam);
...
tts.speak("salam", TextToSpeech.QUEUE_FLUSH, null); //<--This isn't playing my voice file.
tts.speak("shalam", TextToSpeech.QUEUE_FLUSH, null); //<--Neither is this
I am sure of the existence of both files.
Why is that? Is there any restriction on the sound files? For example on their Frequency, or being mono or stereo?
I already checked the docs and saw nothing related.
OK, I found my problem, very silly situation which wasted several hours of mine!! I hope it will help if someone makes my mistake.
We should postpone this mapping of texts to the point TTS is successfully initialized, for example in onInit function:
#Override
public void onInit(int status) {
if(status == TextToSpeech.SUCCESS)
{
tts.setLanguage(Locale.US);
mapVoices();
}
else
...
}
private void mapVoices()
{
tts.addSpeech("salam", "/sdcard/salam.wav");
tts.addSpeech("shalam", "com.company.appname", R.raw.shalam);
//...
}
TextToSpeech tts = new TextToSpeech(context, this);
tts.speak(text, TextToSpeech.QUEUE_ADD, null);
how can i know when speech is finished with speaking, becouse when stop talking i need to execute some extra code. But i have problem becouse i don't knowh how to check if speech is finished with talking.
Is there any option to check this?
Yes, there are two listeners:
API 4-14: OnUtteranceCompletedListener
API 15+: UtteranceProgressListener
I haven't used the UtteranceProgressListener, but the OnUtteranceCompletedListener is very particular. Here are two tips:
Set this listener in the onInit() callback, never before.
You must pass the third parameter params to speak() with a valid KEY_PARAM_UTTERANCE_ID, otherwise this listener is never called.
As for as i know there is no listener for this but we have method called isSpeaking() to check whether TTS engine is busy speaking or not. So that you can take the help of this method to check it is speaking or not
public boolean isDoneSpeaking() {
if(!mTts.isSpeaking())
{
return true;
}
else
{
return false;
}
}