Menu

pocketSphinx: record with bluetooth headset

Help
bamboo
2016-01-28
2019-07-11
  • bamboo

    bamboo - 2016-01-28

    I successfully built the pokectSphinx android demo on my phone, but I want to recognize my speech by using bluetooth headset, which means mute my phone micphone and just use the bluetooth headset.
    I cannot find where I should modify in the android demo project.
    Can somebody help me?

     
    • Nickolay V. Shmyrev

      1) Register receiver to get notified about bluetooth connections:

      BroadcastReceiver connectionReceiver = new BroadcastReceiver() {
              @Override
              public void onReceive(Context context, Intent intent) {
                  int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, -1);
                  Log.d(TAG, "Bluetooth connection state " + state);
                  checkHeadset();
              }
          };
      
            registerReceiver(connectionReceiver, new IntentFilter(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED));
      

      2) When connection is active start Bluetooth SCO:

         @SuppressWarnings("deprecation")
          private void checkHeadset() {
              BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
              if (adapter.getProfileConnectionState(BluetoothProfile.HEADSET) == BluetoothProfile.STATE_CONNECTED) {
      
                   new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                      public void run() {
                          AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                          am.startBluetoothSco();
                          am.setMicrophoneMute(true);
                      }
                  }, HEADSET_ENABLE_TIMEOUT);
              } 
          }
      

      That should make recorder get audio from Bluetooth.

       
      • bamboo

        bamboo - 2016-01-29

        Thank you very much!
        I will try.

         
  • AdrienG

    AdrienG - 2019-07-10

    Hi Nickolay,

    I tried your code, no error, no warning, but I can't use my bluetooth headset with my PocketSphinx application.
    It still works for my phone's microphone however.

    I also tried to mute my phone's mic and then, the sound goes to my bluetooth headset, but both of my mics (phone and headset) can't be used.

    Could you please helping me ?

     
    • Nickolay V. Shmyrev

      It depends a lot on your phone model. You need to make sure audio recording from bluetooth works, it is not related to pocketsphinx at all. You might also get additional details from logcat.

       
      • Nickolay V. Shmyrev

        I.e. bluetooth framework functions differently on different phones. You need to try on different phone models first maybe to see if it works somewhere.

         
  • AdrienG

    AdrienG - 2019-07-11

    Okay, thank's for your answer, it's working fine today for my bluetooth headset with MODE _IN_COMMUNICATION.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.