This is my first post on Stackoverflow. I try to route audio on android smartphone for the past few days but I don't find function to do that properly.
It is for making a Bluetooth Babyphone.
I need to make a routing between smartphone and Bluetooth module. The Bluetooth module is initially used to make Handset, cars Handfree, wireless speaker...
I communicate with A2DP and HFP(Handfree) profiles for the audio side of the project.
I can establish a “sco” connection(connection used with Audio Bluetooth exchanges ) between devices and get back audio from Bluetooth module. But when a connection “sco” is working, I can no more use the speaker and microphone on my smartphone.
I hope to find a solution to use audio on my smartphone and in the same time the audio on my Bluetooth module.
I searched on http://developer.android.com/index.html for a function to route audio.
The AudioManager class has some functions to route audio like setRouting or setParameters but I have any result yet. http://developer.android.com/reference/android/media/AudioManager.html
You can see below the code I use to get audio from babyphone side(Bluetooth module side):
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()
If I can not route audio to smartphone speaker and use “sco” connection in the same time to get back audio from microphone on the babyphone side, I need to know it as soon as possible for changing the direction of my project.
The babyphone program on the smartphone side needs to run on all recent smartphones if possible.
English is not my first language so some sentence may not be correct.
I’m open to any solution.