Android - audio routing function between smartphone and Bluetooth module

This is my first post on Stackoverflow. I have been trying to stream audio to an Android smartphone for the past few days, but I have not found a function to do it right.

It is designed to create a bluetooth bluetooth phone.

I need to route between a smartphone and a Bluetooth module. Originally, the Bluetooth module is used to make the handset, Handfree cars, wireless speaker ...

I communicate with profiles A2DP and HFP (Handfree) for the sound side of the project.

I can establish a sco connection (the connection used with Bluetooth audio exchanges) between devices and return audio from the Bluetooth module. But when the sco connection works, I can no longer use the speaker and microphone on my smartphone.

I hope to find a solution for using sound on my smartphone and at the same time audio on my Bluetooth module.

I was looking for the http://developer.android.com/index.html function for routing sound.

The AudioManager class has some functions for routing audio, such as setRouting or setParameters, but I have some result. http://developer.android.com/reference/android/media/AudioManager.html

Below you can see the code that I use to receive sound from the side of the babyphone (side of the Bluetooth module):

boolean isRecording=true;
int buffersize = 8000;
byte[] buffer = new byte[buffersize];

//audio configuration and SCO Bluetooth connection. 
AudioManager aManager = (AudioManager) getSystemService(AUDIO_SERVICE);
android.os.Process.setThreadPriority(
            android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
aManager.startBluetoothSco();
aManager.setBluetoothScoOn(true);
aManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

//AudioRecord configuation for recording audio from babyphone.
AudioRecord  arec = new AudioRecord(
            MediaRecorder.AudioSource.VOICE_COMMUNICATION,
            8000,
            AudioFormat.CHANNEL_IN_MONO,
            AudioFormat.ENCODING_PCM_16BIT,
            buffersize); 

//AudioTrack configuation for sending audio to smartphone speaker.                
AudioTrack  atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                8000,
                AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                buffersize,
                AudioTrack.MODE_STREAM);

atrack.setPlaybackRate(8000);

//start audio recording and playing.
arec.startRecording();
atrack.play();

while(isRecording) {
    arec.read(buffer, 0, buffersize);

    atrack.write(buffer, 0, buffer.length);
}

arec.stop();
atrack.stop()

"sco" , , , .

babyphone , .

, - .

Im .

+5
1

A2DP . SCO /VoIP/ BT , .

( / , , ), BluetoothSco IN_CALL IN_COMMUNICATION , STREAM_VOICE_CALL BT_SCO, (- ), BT_SCO.

- , - , IN_COMMUNICATION. setBluetoothScoOn(true) " " BT_SCO, DEFAULT VOICE_RECOGNITION BT_SCO .
, BT_SCO , , .
RING, ALARM MUSIC, , BT_SCO, .

+1

All Articles