Kyne H
Kyne H

Reputation: 133

How to use internal speaker to play sound while a 3.5mm jack plugged to record sound using an external microphone

I'm now programming an app to give vocal feedback through internal speaker while user performing some exercises.

Now I want to add a function to record the user's heartbeat and breathe through a stethoscope plugged in the phone by a 3.5mm jack. The problem is that when I plug in the jack, the speaker won't play any sound because the phone think that earpieces were connected and the sound will be played through them.

What I want to achieve is to record the sound by a stethoscope plugged in the phone while play sound through internal speaker.

Basically I use two ways to play sound, MediaPlayer and TextToSpeech.

I searched on the internet, found these articles:

Forcing sound output through speaker in Android

want to play TTS on Bluetooth headset

What they told me to do is to add permission MODIFY_AUDIO_SETTINGS to manifest

declare variables:

MediaPlayer mediaPlayer; 
AudioManager mAudioManager;
HashMap<String, String> mHashAlarm = new HashMap<String, String>();

in OnCreate method:

mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setSpeakerphoneOn(true);
mediaPlayer = MediaPlayer.create(context, R.raw.ding);
mHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_MUSIC));
...
tts.speak(text, TextToSpeech.QUEUE_FLUSH, mHashAlarm);

But neither of them works.

Does anyone know how to achieve this function? Any ideas would be a lot of help. Thanks.

Upvotes: 5

Views: 2143

Answers (1)

Ajith
Ajith

Reputation: 1

Simply purchase a audio splitter...after that u get two ports plug your external mic on one and plug any speaker on another ....

Upvotes: -1

Related Questions