TextToSpeech how to know when speech is finished with speeking - android

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;
}
}

Related

how to access the phone call state in flutter?

I want to know whether the call is disconnected or continued, and based on that I want to perform an action in the application.
Can anyone tell me how to check if the phone call is disconnected or not?
along with that I also want to know if it is received by the end-user or not
any kind of help will be appreciated.
thank you
I think you should take the steps I list below:
One line of code can make a phone call
Wait for any in-flight phone
Calls Watch everything that happens on the phone during a single Call or all
calls.
Keep track of the length of calls, errors, and
call drops.
Now let’s start
Install the plugin
Flutter_phone_state: ^0.5.8
Initiate a call
It is best to make calls from your app whenever you can. This is the best way to find where the call came from.
final phoneCall = FlutterPhoneState.makePhoneCall("480-555-1234");
The truth about a call comes from a PhoneCall object.
showCallInfo(PhoneCall phoneCall) {
print(phoneCall.status);
print(phoneCall.isComplete);
print(phoneCall.events);
}
PhoneCall.events can be read as a stream, and when the call is over, the plugin will gracefully close the stream. The plugin keeps an eye on all calls in progress and will eventually force any call to time out.
watchEvents(PhoneCall phoneCall) {
phoneCall.eventStream.forEach((PhoneCallEvent event) {
print("Event $event");
});
print("Call is complete");
}
You could also just wait until the call is over.
waitForCompletion(PhoneCall phoneCall) async {
await phoneCall.done;
print("Call is completed");
}
Accessing in-flight calls
In-flight calls can be accessed like this:
final `activeCalls = FutterPhoneState.activeCalls;`
Note that activeCalls is a copy of the calls at the time you called it. This copy cannot be changed. It won't be updated on its own.
Watching all events
You can watch all the events instead of just focusing on one call. We recommend using “FlutterPhoneState.phoneCallEventStream” because it includes our own tracking logic, call timeouts, failures, etc.
watchAllPhoneCallEvents() {
FlutterPhoneState.phoneCallEvents.forEach((PhoneCallEvent event) {
final phoneCall = event.call;
print("Got an event $event");
});
print("That loop ^^ won't end");
}
You can sign up to get the raw events if you want to. Keep in mind that there are only so many of these events.
watchAllRawEvents() {
FlutterPhoneState.rawPhoneEvent.forEach((RawPhoneEvent event) {
final phoneCall = event.call;
print("Got an event $event");
});
print("That loop ^^ won't end");

Hindi Text To Speak Issue

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.

Android detecting when lines have been connected during an outgoing call

Just a quick background I'm Running CM7 on a rooted Nexus one.
I am trying to detect when an outgoing call is actually connected: has stopped ringing and the person you are calling has answered. Looking through the forums this seems to be a tough and perhaps unanswered question. I'd really appreciate any insight into this.
In my searching the best I could find was in:
Android : How to get a state that the outgoing call has been answered?
#PattabiRaman said: "instead of detecting the outgoing call connection state, it is easy to get the duration of the last dialed call."
Does he mean that one should get the duration of the last dialed call as the call is in progress? And when that duration goes over 0 then you know?
The class com.android.internal.telephony.CallManager should have information about when the call actually is answered. It has a public static method getInstance() which returns the CallManager instance, and a public method getActiveFgCallState() which returns the current call state as a Call.State enum.
So in theory something like this might work:
Method getFgState = null;
Object cm = null;
try {
Class cmDesc = Class.forName("com.android.internal.telephony.CallManager");
Method getCM = cmDesc.getMethod("getInstance");
getFgState = cmDesc.getMethod("getActiveFgCallState");
cm = getCM.invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
And then repeatedly poll the state:
Object state = getFgState.invoke(cm);
if (state.toString().equals("IDLE")) {
...
} else if (state.toString().equals("ACTIVE")) {
// If the previous state wasn't "ACTIVE" then the
// call has been established.
}
I haven't verified that this actually works. And even if it does you'll have to keep in mind that the API could change, since this isn't something that app developers are supposed to rely on.
I have looked into the code.
It will always give null unless you instantiate a Phone object and set it as default Phone.
But instantiating it needs some System permissions allowed only to system aps.
By using this method:
com.android.internal.telephony.PhoneFactory# public static void makeDefaultPhones(Context context) {
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/com/android/internal/telephony/PhoneFactory.java

In what circumstances does TextToSpeech.isSpeaking() return true?

The documentation says "Checks whether the TTS engine is busy speaking."
But I just implemented a call to isSpeaking() in an onUtteranceCompletedListener, where I have at least 10 pending utterances and in none of them did I received true.
Assuming that isSpeaking() actually works as documented, I must conclude that I am calling it incorrectly.
What are the points in which calling TextToSpeech.isSpeaking() returns a valid result?
Answering myself, thanks to coming across this question (also unanswered):
Problem with isSpeaking() when using Text-to-Speech on Android
The source code of the TtsService class shows:
public boolean isSpeaking() {
return (mSelf.mIsSpeaking && (mSpeechQueue.size() < 1));
}
Which means the TTS engine not only must be speaking but its utterances queue size must be greater than 0.

onUtteranceCompleted() lost if TTS received is too long

I just observed an "undocumented anomaly" in Android's TTS engine: If the text to be spoken is too long (greater than 4K characters), then onUtteranceCompleted() for that particular utterance will never arrive...
Has anyone else come across this?
Is this a known bug or limitation?
What could be done to work around this?
I wasn't aware of the limit, as I prefer smaller chunks of speech (useful if pausing or if activity is paused).
When you call speak, you can add the new utterance to the end of the queue using this for queueMode:
TextToSpeech.QUEUE_ADD
Test to be sure the sentence doesn't sound different, but I think just automatically parsing at the next sentence (or word if needed) after a cutoff length would work.
I am not sure if this will be helpful in your case, but in a similar situation I used an anonymous broadcast reciever with an IntentFilter for TextToSpeech.ACTION_TTS_QUEUE_PROCESSING_COMPLETED as given below
filter = new IntentFilter(TextToSpeech.ACTION_TTS_QUEUE_PROCESSING_COMPLETED);
receiver = new BroadcastReceiver(){
public void onReceive(Context p1, Intent p2)
{
if (p2.getAction().equals(TextToSpeech.ACTION_TTS_QUEUE_PROCESSING_COMPLETED) && tts != null)
{
//
//code here
}
}
};
context.registerReceiver(receiver, filter);
tts = new TextToSpeech(context, this);
Hope this could be of some help for someone at sometime

Categories

Resources