Recording Audio from a Bluetooth Audio Device in Android

前端 未结 3 2008
心在旅途
心在旅途 2020-12-28 11:46

How can I record the voice from a paired Bluetooth audio device (i.e. Moster Clarity Bluetooth Speaker) in Android.

I\'ve paired with the device from within Android,

3条回答
  •  半阙折子戏
    2020-12-28 12:33

    Try this code maybe helpful for you..

    am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    
    registerReceiver(new BroadcastReceiver() {
    
    @Override
    public void onReceive(Context context, Intent intent) {
        int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
        Log.d(TAG, "Audio SCO state: " + state);
    
        if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) { 
            /* 
             * Now the connection has been established to the bluetooth device. 
             * Record audio or whatever (on another thread).With AudioRecord you can          record   with an object created like this:
             * new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
             * AudioFormat.ENCODING_PCM_16BIT, audioBufferSize);
             *
             * After finishing, don't forget to unregister this receiver and
             * to stop the bluetooth connection with am.stopBluetoothSco();
             */
            unregisterReceiver(this);
        }
    
        }
    }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED));
    
    Log.d(TAG, "starting bluetooth");
    am.startBluetoothSco();
    

提交回复
热议问题