how to play audio through speakers during a voice call - android

when a voice call is established, I want to play audio in an stream so that the one at the other end of the call can hear the audio, but as it is mentioned in documents it is not possible.
so I decided to play that audio through the speakers with maximum volume so that the microphone can hear it (in general this a really ugly workaround but as it is going to be done in a special situation in my app, no problem!!!).
now the problem is this that when the call is established the system reduces the volume of my audio. how to solve it ?

Related

Android use internal mic and bluetooth headset as speaker with high quality media protocol during calls

I have bluetooth earbuds with great sound quality and built-in microphones. In my android bluetooth device settings, I have to switches for media profiles: 'Call audio' and 'media audio'
Behavier with both activated:
when mic not needed: high quality sound protocol (1-directional, phone to headset)
when mic needed: switches to low quality sound protocol (2-directional, headset mic also streamed to phone)
Problem: I want better audio quality during calls, because I often am on long calls (mostly on discord) and I want to listen to music in the background with great quality.
Therefore I want to use the 1-directional great protocol and the internal built-in microphone
I did some testing using the audio recorder at first:
turned off 'Call audio' switch in bluetooth settings
earbuds not recognized as possible microphone
recording startet, music on earbuds paused, internal mic was being recorded, I could listen to music in great quality (had to hit play again) on my earbuds with great quality simultaneously -> perfect
So I thought I discoverd the solution, BUT:
On Discord (or any other call app) the earbuds did not show up as a possible speaker.
When listing to music on the earbuds and then joining a call, the audio output immediatly switched to the speaker/earpiece speaker (call audio and music). Probably because the call profile was disabled.
Does anyone have a solution/workaround?
sure, wired headphones would work
Maybe there is a way to redirect my call output from discord to a media stream and then into my earbuds (Then the voice quality on discord would not improve, but I could listen to music in high quality). I found an app (BTmono) doing basically the oppsite for headsets with a call profile only: It converts your media output into a mono stream and outputs it as call audio
maybe, I can somehow mark my earbud's media profile as a call profile too
or maybe anyone got some other workaround that did not come to my mind yet.
I would really appreciate a proper solution to my problem, thanks

Android audio with STREAM_ALARM - how to silence speaker when headphones plugged

I am developing an Android alarm clock app and I am using the STREAM_ALARM for playing the alarm audio. When I plug in headphones during the alarm playing the audio, the audio starts playing in the headphones but also continues playing in the speaker.
But I want to silence the speaker so that the user can plug in his headphones and continue listening to the audio without interrupting any people around him. This might be unusual behavior, but it's very important for this specific alarm clock app.
Maybe I could use STREAM_MUSIC, but:
The docs say that Unless your app is an alarm clock, you should play audio using the STREAM_MUSIC stream.
If the alarm starts ringing and headphones are already plugged in, I do need it to play through the speaker. STREAM_MUSIC does not do this. There might be workarounds, but I need this 100% reliable, so it'd be better to make a workaround for silencing the speaker when needed than a workaround for making it loud when needed.
I am not sure what other consequences it might have, it doesn't seem safe.
So, is there any option to force the speaker to be silent? Using some reflection maybe?
I was also considering changing the stream type on the ActionHeadsetPlug to STREAM_MUSIC, but it requires stopping the audio, recreating the MediaPlayer instance, seeking to the previous position, rebinding any events, other logic etc.. a lot of work for my use case. Silencing the speaker would definitely be better if it's possible.

Does it matter what audio stream I use?

The android audio manager has a large number of different audio streams available, including DTMF, SYSTEM, RING etc.
Not that I'm saying its a good idea, but is there any significant disadvantage to playing audio on a stream other than MUSIC? The standard appears to be to play on the MUSIC stream, but if, for example, I want to use the ringer volume, is there any disadvantage to just playing on the RING stream instead?
There are a number of cases where playing on streams other than music offer some advantages in addition to the case I provided above, but I don't want to risk breaking more important functionality if I can help it.
I'd be curious to hear whether anyone has any experience playing on and/or manipulating other streams, and what side affects, if any, they've encountered (or incurred...)
Why do you need it? I think media stream is enough for any of your purposes.
Look, for example you use ring stream. And for example your program controls it volume. He sets "no volume" => it means that he goes into "vibrate mode" and he cant hear incoming rings because of your application

Play pre-recorded audio into a voice call

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.

how to play a pre-recorded sound in speaker or mic during a call..?

Is this possible to play a pre-recorded sound in speaker or mic during a call.. so that other party could hear it?
Please refer to this first before reading through. The modem processor directly feeds from the mic and since there is not wiring between the app and modem processor, IMHO you cannot route the pre-recorded audio to the other end.
The other party can hear only what the microphone picks up. So, if you play a pre-recorded audio file while in a call on the speaker, and it is loud enough, the mic will pick up the audio and it will be heard at the other end. Not sure if echo cancellation will have an "adverse" effect in this case by eliminating the audio from the speaker.

Categories

Resources