Reputation: 3001
I am developing an application in which I want to generate a speech file i.e. written text using text to speech everytime on a Outgoing call. I am able to detect when a receiver answers the call using an Accessibility Service. Here is the code:-
public class CallDetection extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
Log.i("myaccess", "in window changed");
AccessibilityNodeInfo info = event.getSource();
if (info != null && info.getText() != null) {
String duration = info.getText().toString();
String zeroSeconds = String.format("%02d:%02d", new Object[]{Integer.valueOf(0), Integer.valueOf(0)});
String firstSecond = String.format("%02d:%02d", new Object[]{Integer.valueOf(0), Integer.valueOf(1)});
Log.d("myaccess", "after calculation - " + zeroSeconds + " --- " + firstSecond + " --- " + duration);
if (zeroSeconds.equals(duration) || firstSecond.equals(duration)) {
Toast.makeText(getApplicationContext(), "Call answered", Toast.LENGTH_SHORT).show();
// Your Code goes here
}
info.recycle();
}
}
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Toast.makeText(this, "Service connected", Toast.LENGTH_SHORT).show();
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.notificationTimeout = 0;
info.packageNames = null;
setServiceInfo(info);
}
@Override
public void onInterrupt() {
}
}
Now, I am using text to speech to play the voice but that doesn't work here. Neither I am able to use it in the service nor I can here any voice on another phone. I searched and find android doesn't allow an app to send voice during a call. Is that true? Help me in resolving this problem.
Upvotes: 1
Views: 515
Reputation: 10235
What you found is absolutely right. Android API won't allow access to the voice input directly because of security concerns. Therefore there is no way to achieve what you are trying to do in normal devices.
Another possibility which comes to our mind is to play an audio clip using during the call.See this quote from official docs about using media player during call
You can play back the audio data only to the standard output device. Currently, that is the mobile device speaker or a Bluetooth headset. You cannot play sound files in the conversation audio during a call.
The only hop is a custom OS / hardware which take the provided audio as the microphone input in normal devices.
Upvotes: 3