I'm recording my voice through a Bluetooth headset (ERA JAWBONE) and playing it in realtime on the phone speaker. This works with the following code:
buffer = new byte[buffersize];
android.os.Process.setThreadPriority(
android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
aManager.startBluetoothSco();
aManager.setBluetoothScoOn(true);
aManager.setMode(AudioManager.MODE_NORMAL);
arec = new AudioRecord(
MediaRecorder.AudioSource.VOICE_RECOGNITION,
hz,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
buffersize);
if (AcousticEchoCanceler.isAvailable()) {
AcousticEchoCanceler echoCanceller = AcousticEchoCanceler.create(arec.getAudioSessionId());
if (echoCanceller != null) {
echoCanceller.setEnabled(true);
}
} else { Log.e(TAG, "Echo Canceler not available");}
if (NoiseSuppressor.isAvailable()) {
NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(arec.getAudioSessionId());
if (noiseSuppressor != null) {
noiseSuppressor.setEnabled(true);
}
} else { Log.e(TAG, "Noise Suppressor not available");}
atrack = new AudioTrack(AudioManager.STREAM_MUSIC,
hz,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT,
buffersize,
AudioTrack.MODE_STREAM);
atrack.setPlaybackRate(pbhz);
}
aManager.setStreamSolo(AudioManager.STREAM_MUSIC, true);
arec.startRecording();
atrack.play();
onRecording=true;
Runnable runnable = new Runnable() {
@Override
public void run() {
while (onRecording) {
arec.read(buffer, 0, buffersize);
atrack.write(buffer, 0, buffer.length);
}
}
};
new Thread(runnable).start();
}
But my headset is picking up every sound in the room and starts to echo. When I use the headset to make a call my voice is clear. According to the specs the JawBone uses NoiseAssassin, but I'm pretty sure that it isn't activated when I'm using the code above. Nor is the noisesuppressor or echocanceler available on my device.
Is there a way to filter out the noise and have just a clear voice coming from the phone speaker?