9

I have Integrated PJSIP with android. While making call in my application, the Speaker is working perfectly but Recording microphone volume is too low. My voice is not hearable by other side.

Note: But in some mobiles it's working properly.

Even i tried with adjustStreamVolume(), setStreamVolume(), setMode(),adjustVolume() methods to increase my volume level, it doesn't increase in anyway. Please give me a suggestion to solve this problem to increasing microphone Volume level in Android or from PJSIP.

Thanks in Advance.

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
Nandhakumar Kittusamy
  • 1,066
  • 12
  • 32
  • When you say ~"**in some mobiles it's working properly**", what devices did you mean? – IgorGanapolsky May 17 '17 at 16:53
  • 2
    In moto e3 power, redmi 3s prime mobiles the microphone volume is in acceptable level.But in lenovo k5 plus microphone volume is very low. I don't know how to increase volume for microphone. – Nandhakumar Kittusamy May 17 '17 at 17:00

2 Answers2

5

Problem is Microphone volume level is too low when our application access through microphone. When you got low volume, you need to check multiple things.

One of them is MODE OF THE AUDIO MANAGER when microphone is used.

Getting MODE of the Android Audio manager::

AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
long mode = am.getMode();   
Log.e(TAG,"audio mode "+mode);

Setting MODE of the Android Audio manager::

AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setMode(3);

You can access the mode of audio manager through this above code for your app. There are
1.MODE_NORMAL
2.MODE_RINGTONE
3.MODE_IN_CALL
4.MODE_IN_COMMUNICATION

P.S. : Whenever you change the mode of the AudioManager, please change into MODE_NORMAL after using microphone otherwise it won't work once you restart the mobile.

jafarbtech
  • 6,842
  • 1
  • 36
  • 55
  • 1
    Thanks,am.setMode() is worked perfect for me.My issue:when I's set audiomanager.setSpeakerphoneOn(ture),the speaker's voice is too low even though I had set all volumes to max value and finnally I fixed the issue after use am.setMode(MODE_IN_COMMUNICATION). – aolphn Aug 24 '18 at 06:46
4

It looks like to me setStreamVolume and the like are more used for speakers rather than to control the microphone.

From the PJSIP docs, you can see there is a method called that could adjust the signal level received.

You can use it like the following, where volume is between 0 and 2.0.

pjsua_conf_adjust_rx_level(0, volume);

I saw in a few places that you might need root access to modify this parameter anyway, or that you need to have a MediaTek chip.

What you can do instead is increase the gain from your stream directly. This answer shows you how you could do it, where the gain is also in the same range.

Community
  • 1
  • 1
Preview
  • 35,317
  • 10
  • 92
  • 112
  • Would this leverage the **PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER** constant from audiodev.h? – IgorGanapolsky May 17 '17 at 16:56
  • 1
    @IgorGanapolsky by looking at the `pjmedia_conf_adjust_rx_level` that gets called and [this line](https://github.com/chakrit/pjsip/blob/b0af6c8fc8ed97bb03d3afa4ab42c24f46a9212b/pjmedia/src/pjmedia/conf_switch.c#L989), I don't think that's the case. – Preview May 17 '17 at 17:03
  • @IgorGanapolsky PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER is just for speaker only know, but i want for increasing microphone volume. – Nandhakumar Kittusamy May 17 '17 at 17:13
  • @Apercu thanks for your solution.But If thats the problem means, why its working on some mobiles perfectly. And I already checked this method and it remains same low volume. I think its device specific, not in pjsip and need to increase the mic volume for my dialer app in android app level. Any other ideas to increase mic volume level particularly in android ? – Nandhakumar Kittusamy May 17 '17 at 17:21
  • @NandhaKumar did you tried to increase the gain of your stream instead as showed in the answer I linked? – Preview May 17 '17 at 17:23
  • @Apercu I tried this method pjsua_conf_adjust_rx_level(0, 2.0) and it doesnt increase volume level of microphone. – Nandhakumar Kittusamy May 17 '17 at 17:26
  • I'm talking about [this answer](http://stackoverflow.com/a/25442217/2054072), where you basically manually modify your data stream to increase the gain. Modifying the microphone level requires won't work in some devices, you have to take another route. – Preview May 17 '17 at 17:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144488/discussion-between-nandha-kumar-and-apercu). – Nandhakumar Kittusamy May 17 '17 at 17:34
  • when using recording through microphone, it shows E/AudioPolicyManager: unknown stream type 13 error in logcat window. – Nandhakumar Kittusamy May 18 '17 at 06:15