Play pre-recorded audio into a voice call - android

The question have been asked before ( How to play an audio file on a voice call in android, play an audio file on a voice call etc), but I will ask it anyway: Is it possible to play an audio file into an ongoing voice call. I know the short answer is "No", but I have not figured out why it is not possible.
I know the SDK does not have support for it, but would it by any chance be possible in some way to write your own code that handles this, maybe with help from C/C++ code (using the NDK)? Does anyone have any idea on how to solve this? Or is the answer a strict "no, you cannot play pre-recorded audio into a voice call"?
I do not really care if the solution does not work on all devices, as long as I can find some devices that support the solution, and I can consider the get root access if that is needed.

I used Audiotrack to play audio with stream set to STREAM_VOICE_CALL during voice call on my One-Plus(Test Device) and it worked perfectly, however the audio which I speak is heard clearly and the music played is not heard. Probably because of the noise cancellation feature applied. I used Lollipop based Rom for this.So the answer is yes we can play.

Related

Why it is not possible to play an audio file on a voice call in android

This question might seem to be a repetition of the questions such as following:
How to play an audio file on a voice call in android
Background Audio for a Call in Progress - Possible?
The answers of these questions suggests that it is not possible to play a pre-recorded audio on a voice call in android. I want to know why it is not possible? What is the limitation (hardware/software)? Is it really a limitation or done purposely? Can we alter the source code of android to make it possible?
I think this is a limitation, imposed for security reasons and restricted at the OS level.
Let's analyze the security threat, first of all. If you were able to play custom audio files to the callee, a whole world of cons opens up: you could trick customer supports, you could pretend to be someone else, you could give unauthorized purchase confirmations, and so on. For this reason, neither Android nor iOS allows this functionality.
On Android, you won't be able to do so in a programmatic way, simply because the current APIs won't allow you to do so. It is stated in the official documentation as well, as pointed out here. If you dig into the source code, you can probably enable this feature by accessing the microphone output during a phone call, but that would require running your custom version of Android. A good starting point would be the AudioTrack source, available here.
EDIT: a good example of an audio mod involves enabling the Nexus 5 earpiece as a second loudspeaker (requires root). Can be found here.
After a thorough research, what I have come to know is that there are more than one limitations/hurdles to make it possible. These limitations/hurdles are at three different levels.
First limitation is at API level, because there is no high-level API to play sound files in the conversation audio during a call as mentioned in Android official documentation.
Second limitation is at Radio Interface Layer (RIL). RIL passes on complete control of the call to Radio Daemon (rild) of the Linux library which then further passes the control to the vendor RIL. That means we cannot manipulate voice call in android source code.
Even if we are able to remove these two limitations, we may still not be able to play audio file to an ongoing voice call. Because there is a third limitation. Every vendor has their own library of RIL that communicates with Radio Daemon (rild). This requires that vendor RIL to be open source which is not actually. Hardware vendors do not usually make their device drivers code available.
Detail discussion on this topic is present at this link.
This is software related due to the prioritization of audio routing in Android.
Take a look into the CallManager where you can dig into the method setAudioMode(). After the audio mode was set to MODE_IN_COMMUNICATION the following code is called
audioManager.requestAudioFocusForCall(AudioManager.STREAM_VOICE_CALL,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
From this point on the telephony service has the highest priority and won't let any other audio play in parallel.
Note: 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.
See official link
http://developer.android.com/guide/topics/media/mediaplayer.html
By implementing the AudioManager.OnAudioFocusChangeListener you can get the state of the audiomanager. so by this if any music is playing in the background you can get the AudioManager states(playing and pausing is completely in developer hands) similarly......
Some of the native music players in android device where handling this, they restrict the music when call is in TelephonyManager.EXTRA_STATE_OFFHOOK.so this scenario is also completely in developer hand (whether to handle or not) if he is not handling both will play parallel y

Sending Streaming Audio on a Phone call

I have seen that it seems to be imposible to send an audio (mp3, ogg,...) to a phone call, but i wanted to know if it's possible to play an mp3 in the phone so it's reproduced in max volume when call established.
Unfortunately, that's not possible. There's no API or hardware support for that. Someone else asked a similar question: Call Audio Stream Modification in Android 4.0 ICS

Android: Playing audio file though telephone line

I have been searching the internet for an answer, on how to play an audio file through the telephone line (See example if you wonder what I mean). Now I have come to this site to find the answer:
Is it possible to play an audio file located on your telephone, so that the caller can hear it, without turning on your speaker and let it blast it out loud? If so, does anybody know a site to look it up at?
Example:
Peter calls Annie. Annie answers the call, and decides to play her favorite music to Peter, but she doesn't want to turn on her speaker, because her parents are sleeping in the room next to her.
I know that a telecommunications server is able to play music when people are on hold, waiting for an employee or in a queue, but is an Android phone able to do the same?
You can't do this.
All audio calls are routed through the baseband chip at a hardware level. The underlying telephony technology isn't exposed to the OS, much less the Android APIs.
So basically, this is impossible, unless you're willing to settle for playing it over the loudspeaker and hoping it gets picked up clearly.

Play an audio file as soon as Text To Speech is completed in Android

I'm trying to develop an Android app where as soon as the text to speech is completed an audio file has to be played. How to do this?
If I didn't get wrong idea, you want to use text-to-speech to read some text and store the speech audio into phone in the meantime? And play the audio later?
Have you checked AudioRecordTest? You can record audio and then play it later. Worth to try but I don't think you can get a good quality from the microphone. Hope this helps:)
By the way, as far as I know, android only support to record from mic for unrooted phone, which you can check here. Let me know if you can record sound source from the android system.
I have found the solution and that is in the method onUtteranceCompletedListener() we can know whether the speech is stopped or not and then we can write the code to play the audio file

Android: Accessing the microphone simultaneously (RecognizerIntent + own app)

my app uses the RecognizerIntent to record the user's voice and doing some speech recognition.
Now, I'd like to compare the results to some open source speech recognition engines. Most of them take an audio file as input. My thought was, to capture the sound from the Android's microphone, and start the RecognizerIntent at the same time. But it seems, that accessing the microphone is exclusive.
Is it possible to use the RecognizerIntent with a recorded audio stream?
Is it possible to access the microphone simultaneously with two Activites?
I have tried to find a solution to the same problem and have not had success. One other approach we explored was to access the web service that Google uses for recognition. I posted a question at Google's voice search speech recognition service, but it still goes unanswered.
There was a good post at Voice recognition on android with recorded sound clip? that dealt with this question and I believe the answer came from a Google employee.
Unfortunately the answer to both of your questions is no, but there are plans to extend this for Gingerbread and 3.0: http://www.mobiclue.com/android-3-0-gingerbread-features-supported-phones.html
I know for sure that is possible to use RecognizerIntent and save the audio, the question is how?
You can see in Google Keep Android applications doing it once you click in the microphone.

Categories

Resources