Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream audio to a phone call Android

I am attempting to send an audio stream out over a phone call on Android.

For example, to create an app which would play some custom on-hold music, or answer a call and play a recording/audio file. I know it is possible to have an app automatically answer a call, but can it send audio to the caller?

If it is possible, please let me know what classes/functions handle this.

like image 778
ventres Avatar asked Mar 11 '11 04:03

ventres


People also ask

How can I play audio during call in Android?

Turn on the hands free function of your phone. Create a media player, set the media source, set the volume to 1.0f (highest) and call player. start() . If the microphone and speakers on the phone are of reasonable quality, the other party to the call will hear the music.

How do you play a sound on a call?

Glorious. have you tried having the application open that creates the sounds you want (such as a soundboard) or having your music player (android os, or other) open while the phone call is active? hold-homekey switch to the sound app and play the sound.

How do I share audio while on a call?

To start screen sharing when on a call, you have to press the Share Screen button (two overlapping squares) or press the 3dots (more) button and select the Share Screen option. Whether the one or the other option is available depends on the size of the call window.

Can you stream audio from one phone to another?

Open up the music player on your host device and make sure that all your Android gadgets are connected to the same WiFi network. Then you can stream the audio and track information to phones or tablets running the companion SoundSeeder Speaker app.


2 Answers

Writing to the phone call stream IS possible, but not from the app level on a stock (non rooted) phone.

When a phone call is initiated the mic is "typically" (really depends on the specific phone) routed directly to the baseband, ie skipping the main processor altogether.

For outgoing audio: mic->codec->baseband For incoming audio: baseband->codec->speaker

If it were always routed: mic->codec->mainprocessor->codec->baseband

Then the stream would be "presumably" available if the Android APIs (frameworks) supported accessing it.

The reason I say it is possible is because the audio (for nearly all smartphones now) is connected via SlimBus This allows dynamic changing of audio paths. It is however done in the kernel via the codec driver living in ALSA.

So.... were you so motivated, you could get the source for the Linux kernel for a phone and modify the codec/ALSA driver to allow you to change what happens when the call audio path is setup.

Of course then you would incur latency with the new path, breaking the call/latency standards AT&T setup (that Audience helped them write...) and the baseband chip might reject your audio as it's not timely.

Lastly you would need to modify the Android source (frameworks) to grow the API to support injecting audio onto that stream. (You'd need to make big mods to mediaserver, audioflinger in particular...)

It's complicated, but there is your answer. Cheers, :-)

like image 126
kieran Avatar answered Oct 29 '22 13:10

kieran


I know the apps that are already sending all system audio to phone's earpiece even the songs you plays in your media player without root or any other special permission.

After some research I found that it can be done using Audio Manager class. For example

 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
 audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
 audioManager.setSpeakerphoneOn(false);

Why not to set default output speakers as device earpiece and then play audio using MediaPlayer class?

like image 20
Muhammad Saqib Avatar answered Oct 29 '22 13:10

Muhammad Saqib