I am developing an Android app which have to use both the smartphone's inbuilt mic and a bluetooth headset mic. I want to add a radio button in my app, so that users can freely choose to use either the inbuilt mic or the bluetooth headset mic.
When a user choose bluetooth headset mic, the bluetooth headset mic should simulate the inbuilt mic, that is, the bluetooth headset mic exactly replaces the inbuilt mic.
How to implement it?
I have solved my own question!
The answer is AudioManager
After my bluetooth headset has connected to my smart phone. There is just two steps to do:
Step one:
mAudioManager.startBluetoothSco();
Step two:
mAudioManager.setBluetoothScoOn(true);
Then my headset bluetooth's mic is working!
Related
I'm new in android development, I'm developing a simple application that plays a music on button click through speaker , I would like to know how to route an audio to A2DP bluetooth device after paring with the A2DP device.
What are the configurations of AudioManager and other presets?
Thanks!
I am currently recognizing Hot word(like "ok google") using pocketsphinx library.
The app works fine except that it always uses only the phone's mic to recognize the speech.
My use case is something like this:
I listen for a hot word and use the MediaPlayer to play some music.
Keep listening for next commands while keeping the music being played and react accordingly.
The app works fine and the music is played via the bluetooth headset and the voice is also simultaneously recognized, but it always uses the phone's mic. Even though the bluetooth headset is connected or not connected, it still uses the phone's mic.
I tried using:
AudioManager mAudioManager =
(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.startBluetoothSco();
I tried using:
AudioManager mAudioManager =
(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.startBluetoothSco();
In both the approaches, it cuts off the music and listens in bluetooth mic.
I need an approach where the Music player is not cut from bluetooth headset but still I am able to speech recognize from bluetooth headset.
For example:
I was listening to music via bluetooth headset.
I opened voice recording app(https://play.google.com/store/apps/details?id=com.andrwq.recorder)
I am able to record the audio through bluetooth headset even while listening to music.
This makes me feel that it is possible but I don't know how.
Please help me out. Thanks in advance.
It is correct to start SCO mode, after that pocketsphinx will listen for bluetooth headset.
To disable phone microphone while in sco mode use am.setMicrophoneMute(true);
To play audio through SCO you need the player to play through STREAM_VOICE_CALL. Maybe player must be restarted after SCO switch.
If I set AudioManager mode to MODE_IN_COMMUNICATION, and set the Media Player stream to STREAM_VOICE_CALL, I can route the audio to the speakerphone or the internal handset speaker just fine. And if it's routed to the internal speaker, and a wired headset is plugged int, it automatically routes to it. However, I can't figure out a way to route the audio to an A2DP headset (without changing the audio mode to MODE_NORMAL, or the stream to STREAM_MUSIC). My problem is that using MODE_NORMAL and STREAM_VOICE_CALL causes problems on some devices, and using STREAM_MUSIC is a problem if there is already music playing in the background, then my app "mixes" with that background music.
So, I was hoping that there was a way to force the audio to the A2DP headset using the MODE_IN_COMMUNICATION and STREAM_VOICE_CALL combination. Is that possible?
Perhaps it works on some devices, but if you care about compatibility across the majority of devices then the answer is "No".
When the phone state is MODE_IN_CALL or MODE_IN_COMMUNICATION all streams will typically follow the PHONE routing strategy. This means that routing to A2DP will not be allowed since:
1) A2DP doesn't support two-way voice anyway.
2) If your BT accessory supports the Hands-free profile it will use a SCO link for the voice audio, and the ACL channel used for A2DP should be closed to avoid interference between the two.
I would like to capture the audio from a specific channel (eg. I have a 3.5mm headset and a Bluetooth headset both connected to an android phone. Right now, it receives audio from both sources when I use "AudioSource.MIC" and I would like to capture an audio from a bluetooth headset only) is there anyway I can specify the audio channel programatically ?
How can I programmatically capture audio from a specific channel on Android?
My device is the Nexus One, running Android 2.3.7, Bluetooth headset Jabra BT 2035
I'm using my Nexus One with Android 2.2 Froyo in my car dock. For the audio output I'm using a a2dp receiver which is hooked up to my car stereo.
Now, when I put the phone in the car dock it automatically connects to the car dock but not to my a2dp receiver, I have connect it manually in the settings (already paired).
I'm also using a custom app for audio playback. I thougt I maybe could force the a2dp connection to the a2dp receiver. But as far as I know, the default Bluetooth API does not support such a thing.
Is there any Intent for establishing the connection, or any other way? I would also accept an undocumented solution.
I fixed this recently with the app A2DP volume.
My issue was my lg p920 on android 2.3.5 would connect to handsfree and a2dp stereo audio with my Sony car stereo mex bt3950ou (many other brands have the same issue).
Once the car was turned off and back on again ie. in turning the ignition from acc to start, the connection would be lost and only the handsfree would reconnect.
A2DP volume can be configured to force reconnect the stereo audio connection, see instructions on the A2DP volume site.
See your issue with twin BT devices. You can get BT Visor mount systems that do this. The BB version will stream A2DP music from the device AND allow you to take calls. The drawback is it uses FM to get the sound to your headunit so sound quality will be lower than native BT.
The technique is demonstrated in this app: http://code.google.com/p/a2dpvolume/A2DP Volume
Look at service.java and the IADL file.