How to bring audio from microphone to speaker on Android? - android

My problem is when I talk into the microphone, I want my sound to go to speaker of the phone which has Android OS. I think "MediaPlayer" class can't do it. Do you have any way?

Here you are not clear in which scenario you are going to do this but however it is possible to do using AudioManager, you can set your modes and audio services. For more details refer this link :
AudioManager

Related

Is there any way to avoid an external microphone from recording?

I'm building an app that records the user's voice, and I would like to know if there is any way to choose which microphone the application is going to use to record the sound.
My target is to mute the external microphone if the user has one, and let the internal microphone, which is embedded on the smartphone, work.
Does AudioManager offers this options?
Thank you.

how to mute microphone in android by java programming

I am working on project that needs to mute the android microphone to avoiding record audio by any other apps.
I'm trying to googling and i found how to mute microphone but the articles just mute the microphone on during a call
code :
AudioManager audM = (AudioManager) m_instance.getSystemService(Context.AUDIO_SERVICE);
audM.setMicrophoneMute(true);
I need an article to mute the microphone on device that other apps can not record at all.
please help me to do that
Android AudioManager, provides all methods needed to play with mic. but your question has to do with a "global" hardware setup - not inside your app - so if Android OS does not provide that functionality, I think the only think you can do is directly blocking the mic to other apps, or block other apps while your code executes .. did you search APIs that does that ?
As for below thread, it seems that if your app initializes the mic, it wont be available for other apps to use it, I didn't check that.
Here is the thread:
How to block the mic for another app to use?

Turn off microphone in android

I want to turn off or disable the microphone during a call.
I searched, but I got almost nothing. Some people say it is not possible in android.
How do I turn off the microphone?
You can't completely disable the microphone. But you can play around the audio manager, to mute it etc...
AudioManager

Set the volume control stream from a service on Android

I'm working on a music app which consists in a Service playing music while other apps are running.
In order to enjoy the music and only the music, the Service mutes all the other apps. In order to do that, it mutes STREAM_MUSIC and play music over STREAM_VOICE_CALL (found that solution to mute other apps here)
As the Service uses STREAM_VOICE_CALL to play music, what I'm trying to find is a way to make the volume buttons control this stream when a sound is playing.
What I already tried:
setVolumeControlStream: only works in Activities
Capturing volume keys pressed events: Services do not receive such events (source)
audioManager.setMode(AudioManager.MODE_IN_CALL) : does not work in my case. Plus, the SDK documentation states that this "mode should only be used by the telephony application when it places a phone call".
At this point, I'm out of options and any help would be appreciated. Thanks!
I would personally not suggest you to STREAM_VOICE_CALL as it is meant to be recommended to use it for Voice calls as compared to media playback. Using this may prevent you from using features exposed by Android for media playback.
Having said this & taking into consideration your use-case, I think you need to look for changing 'call volume' level as compared to 'media volume' level.
Have a look at the MediaPlaybackService.java as used in the stock Music Player app and try to customize it as per your needs.
I havn't tried it myself. but looks like it should work. Kindly try it out.
m_audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
m_audioManager.setMode(AudioManager.MODE_IN_CALL);

mute sound through phone speaker Android api

I want the to mute all sounds coming through the phone speaker but keep the sounds going through the headphones. Is this possible?
I was looking at:
setMicrophoneMute(true);
and
setSpeakerphoneOn(false);
but neither seem to have any affect. Is this even possible? I have this permission in my manifest:
I couldn't see any methods that would accomplish what I want in the audio manager but maybe I just don't understand the api.

Categories

Resources