Voice recognition with bluetooth headset - android

I have an app which uses voice recognition and tts. I want to use this app through bluetooth headset. I used code from this question: Using the Android RecognizerIntent with a bluetooth headset
Unfotunately, it did not work for me neither recording nor playing. I added in startBluetooth11 method:
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
This make recording working. But still can't get microphone to work.

Related

how to set MediaRecoder audiosource.Mic to BT headset

I had building a recording app, it support recording by mobile mic.
but even I had conncect to headset,it still recording from mobile mic, not headset.
In AudioRecord, seems doesn't has parameter to setting to headset.
does it possible to set recording source to headset?

How to simulate inbuilt microphone on Android?

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!

speech recognition through bluetooth headset in android while playing music

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.

Android Bluetooth App audioManager issues

I am developing an app to control a speaker. I want the app to be able to playback music, do karaoke (play music and mic at same time), and provide a basic EQ to the user. My problem so far has been playing music through Bluetooth at all. My app: -discovers all Bluetooth speakers nearby -puts them in a list -pairs with clicked device and sends user to Bluetooth settings to connect to it
Now my problem is successfully playing music over the bluetooth speakers. I use a AudioManager and set it to play over SCO:
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.startBluetoothSco();
audioManager.setBluetoothScoOn(true);
And then try to play a music file, but this only plays over the devices speakers and not the connected Bluetooth speakers.
So my question is what am i missing? I read a bit about a A2DP sink but it seems to not be available in recent versions. Any suggestions? Thanks in advance.
TDLR: How do I playback music to paired Bluetooth speakers?
The startBluetoothSco() method returns before SCO is setup. You need to register a BroadcastReceiver for ACTION_SCO_AUDIO_STATE_UPDATED before calling the above method.
http://developer.android.com/reference/android/media/AudioManager.html#startBluetoothSco%28%29
it's a sticky intent to so you can always check the status before calling the setBluetoothScoOn(true).

Bluetooth SCO to single android application, not to entire android system

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.

Categories

Resources