Is it possible to record an audio (not a phone call) using the bluetooth input and not the device microphone?
I am able to playback whatever am saying through device's mic but not able to figure out how to use the bluetooth mic instead.
Any assistance would be greatly appreciated.
(Edited)
I got it working by using following two lines of code
startBluetoothSco();
setBluetoothScoOn(true);
Got the bluetooth headset play back whatever am saying by using
STREAM_VOICE_CALL in audioTrack initialization.
Related
I'm trying to correctly setup bluetooth SCO in my app. After many attempts it seems that I've found a way to enable it "almost" reliably, in the sense that it works almost always, but in one case: if I launch my app and AFTER this I pair the headset, the headset mic is not picked (the phone mic is picked instead), while the headset earphones are correctly picked.
If instead I pair the headset BEFORE launching the app, everything seems to work fine.
The strange thing is that, even when the phone mic is picked, calling getRoutedDevice() on my AudioRecord object returns the bluetooth headset.
I tried to use SetPreferredDevice on the AudioRecord object, but apparently it has no effect.
The only way I found to ALWAYS pick the headset microphone is to call
audioManager.setMode(AudioManager.MODE_NORMAL);
However in this case, the output comes from the phone speaker and not from the BT headset earphones!
If instead i call:
audioManager.setMode(AudioManager.MODE_IN_CALL);
the output comes consistently (and correctly) from the BT headset earphones, but I have the above mentioned mic issue (pairing the headset after launching the app, the phone mic is picked instead of the BT headset one).
The sequence I am using is:
I have a thread that checks if a bluetooth headset is connected and works pretty much reliably.
When isHeadsetConnected is true I do:
arec.stop(); // my AudioRecord object
atrack.stop(); // my AudioTrack object
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.startBluetoothSco();
In the listener of AudioManager.EXTRA_SCO_AUDIO_STATE, when I receive SCO_AUDIO_STATE_CONNECTED) I do:
audioManager.setBluetoothScoOn(true);
atrack.play();
arec.startRecording();
After struggling a lot, this seems to be the "almost" perfect sequence, with the caveat that it does not work fully if the first pairing is made with the application running.
I've made an attempt to pair the same headset during a Whatsapp call, and the bluetooth headset starts without any problem both input and output, so THERE MUST be a way to accomplish this!
I have read tons of questions/answers but none of these seems to consistently solve my problem.
I am using Android 11 on a CAT S62 Pro.
Due to some deprecated API, I'm looking for code to know which device is routing current audio Stream. I can list all devices, know if the headset is connected but the API says connected but not routing. Now, I want to check, how to check which one is routing audio at this time.
I found in documentation but don't know how to use: https://developer.android.com/reference/android/media/AudioRouting.html
Any ideas?
I'm trying to send audio over my cars speakers without having the cars audio input set to bluetooth. It supports the A2DP profile, and I also managed to get it to work. But that only works when I manually set the input to Bluetooth.
But I would like to 'force' the audio being sent over the speakers.
I previously had an iPhone. The Google Maps app would 'call' itself everything it would pronounce the directions. So my car would see it is an incoming call and play the audio over the speakers.
I looked around the internet, and it seems I need to use the HSF profile to pull of the same trick.
The documentation states that HSF is supported, but it does not show me how to do it. I also found exactly what I needed in the documentation. It states the following:
NOTE: up to and including API version JELLY_BEAN_MR1, this method initiates a virtual voice call to the bluetooth headset. After API version JELLY_BEAN_MR2 only a raw SCO audio connection is established.
So initiating virtual voice calls was possible. I would like to know how to do that now. Any other ideas on how to do this would also be very helpfull.
Am a beginner in android and I currently working in a project for to record the incoming and outgoing calls in android, but I can't hear receiver voice and I can hear only the dial-er voice. If I switch on the loud speaker then I can hear both the voices. But that's not what I need, I want to record each side of voices clearly without the help of loud speaker. Please advice.
Recording calls can be a challenge as many manufacturers don't allow it(due to legal issues).
For the ones who do you need to access mic via VOICE_CALL permission in manifest to record calls.
use:
audioSource = MediaRecorder.AudioSource.VOICE_CALL
I am using following code in my application to use bluetooth headset for audio IN and OUT. It is working fine.
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
am.startBluetoothSco();
am.setBluetoothScoOn(true);
But, When I played song using Music Player app, along with my application also running, the song is coming in bluetooth headset. This is because I changed the Audio Manager of android system to Bluetooth SCO.
But my requirement is the audio IN and OUT must work with bluetooth headset to my application only and it should not disturb other apps, Is it possible ?? or not ??
Please provide your valuable suggestions. Any help will be appreciated. Thanks.
When you add a SCO channel you are essentially adding an audio channel. Think of it like a wired handsfree. When you connect the handsfree all audio is routed to it and not just one specific applications's audio. To use the BT headset only for your app, connect the SCO channel when the app starts and disconnect when the app is exited or goes into background.