muchumanoj
muchumanoj

Reputation: 125

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:

  1. I listen for a hot word and use the MediaPlayer to play some music.
  2. 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.

Upvotes: 4

Views: 1619

Answers (1)

Nikolay Shmyrev
Nikolay Shmyrev

Reputation: 25210

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.

Upvotes: 1

Related Questions