Is there is any android code to pick the voice from the other side in the call?
meaning while I'm speaking with another person in my Phone I can Play a speaker that picks the voice, can I direct this voice to my application to record, recognize it, or convert to text?
Since my target is to convert the voice in the call to text.
Thanks in advance.
Use Broadcast Receiver to handle calls
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
}else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK){
//apply recording here
}else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
//stop recording
}
}
To convert Voice to Text Follow this Link
You can record from AudioSource.VOICE_DOWNLINK. Keep in mind though that this might not work on every single Android phone out there, and that voice call audio is quite heavily compressed and therefore might not give you any good results from a Speech-To-Text engine.
Related
I have a simple application that needs to call a number and speech-to-text (as best as possible) whatever the other party is saying.
Simply put, if the other party says "Hello", then "Hello" would be displayed on the screen.
I can make a call using Intent.ACTION_CALL:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:91234567"));
startActivity(callIntent);
However, how do I continue from there, to convert the received audio signals to text?
In Android, you cannot access or modify the call audio stream. Due to this, you cannot get what is being spoken, and hence cannot convert it to text.
This app isn't possible on Android.
I'm working on an app which allows user to take voice notes. For this I'm using the AudioRecorder to constantly obtain audio data from microphone and process it into Mp3.
It all worked great until recently I found out that if I receive/make a call while my app is running in background the other party can't hear me. Clicking on mute/unmute button on dialer screen doesn't do anything - the microphone seems to be disabled until I stop my app.
Now the question is how can I handle this situation? Is my only option is to release AudioRecorder once a voice call is started? I'm perfectly ok if AudioRecorder would just skip the audio data from microphone during the call, but the situation when user can communicate because of the app is unacceptable.
Thanks,
Only 1 app can use the mic at any given time. You might want to use PhoneStateListener so that you can release the recorder when the phone rings or is off the hook.
You can intercept incoming calls using PHONE_STATE action as part of a BroadcastReceiver. Then, in your onReceive function of your receiver, you would check states of the phone:
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
//Phone is ringing
}else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK){
//Call received
}else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
//Call Dropped or rejected
}
}
Do not forget to add the neccessary permissions in your manifest.
Likewise, you can intercept outgoing calls as well. Here is a nice tutorial explaining how to do both.
The rest is about stopping and resuming recorder depending on what you intercept.
Could it be possible now, which we can develop an Android application having the following requirement for its working steps
Automatic receive the call, then
Play some sound out to the caller, wait for DTMF response, then
Record the caller sound (in the case that they permit, by pressing 1 as DTMF response)
Callee can play back the recoreded sound later.
Thank for all answers in advance .....
Hey I am also making same application...for Automatic receive call you need to change Source Code of android. I have done it successfully with froyo 2.2. There is method answerCall(Phone phone) in PhoneUtils.java file with that you can automatic receive call.
I am also searching for DTMF....but till now i didn't get anything which can be helpful....for DTMF decoding....
the first point seems possible. check the state of call if it is ringing state the program can auto attend it for you..you can find more information in this link.
http://www.devlper.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/
http://prasanta-paul.blogspot.com/2010/09/call-control-in-android.html
Once ACTION_NEW_OUTGOING_CALL has been broadcasted, I need to capture the following event of the other party answer. Could you advice on how to achieve that please? I know it is possible as the Android dialer app changes the green Android icon to the person's photo exactly when they pick up.
UPDATED: I've had a look at the source of the app on Android handling the outgoing calls. I noticed the following method in ContactsUtils:
/**
* Kick off an intent to initiate a call.
*/
public static void initiateCall(Context context, CharSequence
phoneNumber) {
Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
Uri.fromParts("tel", phoneNumber.toString(), null));
context.startActivity(intent); }
I guess my answer is in the activity listening for Intent.ACTION_CALL_PRIVILEGED. So to rephrase my question: Does anyone know which activity handles Intent.ACTION_CALL_PRIVILEGED?
I don't think there's such API and also there's no API for sending DTMFs due to the same reason that you can't tell when the call is being connected.
It does not necessarily needs to be possible to capture this as an outside app. The green android icon is a part of the application that controls the call, so it does not need a broadcast to change the icon.
As far as android's telephony manager is concerned u cannot detect programmatically whether the call has been answered or not. This is to say that u do not have the option to know when the user picked the phone at other end.
Android has got 3 states of telephony manager and none of them are capable of detecting whether the call was actually answerd or not(IN CASE OF OUTGOING CALLS)
The only way you may be able to do this is by parsing the Logcat logs, no PhoneStateListener event is available for that.
Some are asking for it here: https://code.google.com/p/android/issues/detail?id=14266
Anyway, in versions above Android 4.2 as Logcat is "sandboxed" it may be impossible...
I've used the voice recognition feature on Android and I love it. It's one of my customers' most praised features. However, the format is somewhat restrictive. You have to call the recognizer intent, have it send the recording for transcription to google, and wait for the text back.
Some of my ideas would require recording the audio within my app and then sending the clip to google for transcription.
Is there any way I can send an audio clip to be processed with speech to text?
I got a solution that is working well to have speech recognizing and audio recording. Here is the link to a simple Android project I created to show the solution's working. Also, I put some print screens inside the project to illustrate the app.
I'm gonna try to explain briefly the approach I used. I combined two features in that project: Google Speech API and Flac recording.
Google Speech API is called through HTTP connections. Mike Pultz gives more details about the API:
"(...) the new [Google] API is a full-duplex streaming API. What this means, is that it actually uses two HTTP connections- one POST request to upload the content as a “live” chunked stream, and a second GET request to access the results, which makes much more sense for longer audio samples, or for streaming audio."
However, this API needs to receive a FLAC sound file to work properly. That makes us to go to the second part: Flac recording
I implemented Flac recording in that project through extracting and adapting some pieces of code and libraries from an open source app called AudioBoo. AudioBoo uses native code to record and play flac format.
Thus, it's possible to record a flac sound, send it to Google Speech API, get the text, and play the sound that was just recorded.
The project I created has the basic principles to make it work and can be improved for specific situations. In order to make it work in a different scenario, it's necessary to get a Google Speech API key, which is obtained by being part of Google Chromium-dev group. I left one key in that project just to show it's working, but I'll remove it eventually. If someone needs more information about it, let me know cause I'm not able to put more than 2 links in this post.
Unfortunately not at this time. The only interface currently supported by Android's voice recognition service is the RecognizerIntent, which doesn't allow you to provide your own sound data.
If this is something you'd like to see, file a feature request at http://b.android.com. This is also tangentially related to existing issue 4541.
As far as I know there is still no way to directly send an audio clip to Google for transcription. However, Froyo (API level 8) introduced the SpeechRecognizer class, which provides direct access to the speech recognition service. So, for example, you can start playback of an audio clip and have your Activity start the speech recognizer listening in the background, which will return results after completion to a user-defined listener callback method.
The following sample code should be defined within an Activity since SpeechRecognizer's methods must be run in the main application thread. Also you will need to add the RECORD_AUDIO permission to your AndroidManifest.xml.
boolean available = SpeechRecognizer.isRecognitionAvailable(this);
if (available) {
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new RecognitionListener() {
#Override
public void onResults(Bundle results) {
// process results here
}
// define your other overloaded listener methods here
});
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// the following appears to be a requirement, but can be a "dummy" value
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.dummy");
// define any other intent extras you want
// start playback of audio clip here
// this will start the speech recognizer service in the background
// without starting a separate activity
sr.startListening(intent);
}
You can also define your own speech recognition service by extending RecognitionService, but that is beyond the scope of this answer :)