From the android side, I think the best solution is to open the connection to the service in your computer:
URL url = new URL("http://192.186.0.1/path/to/service");
URLConnection connection = url.openConnection();
Get it as an OutputStream:
OutputStream out = new BufferedStream(connection.getOutputStream());
and then use a AudioRecord
to send though the recorded data:
public static final int DEFAULT_SAMPLE_RATE = 8000;
private static final int DEFAULT_BUFFER_SIZE = 4096;
private static final int CALLBACK_PERIOD = 4000;
AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT,
DEFAULT_SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT,
AudioFormat.ENCODING_DEFAULT, DEFAULT_BUFFER_SIZE);
recorder.setPositionNotificationPeriod(CALLBACK_PERIOD);
int bytesRead = 0;
ByteBuffer buffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE);
while ((bytesRead = recorder.read(buffer, DEFAULT_BUFFER_SIZE)) > 0) {
out.write(buffer.array(), 0, bytesRead);
}
All this should be done on a separate thread of course to avoid crashing the app and a mechanism to handle when the recording stops or the connection is lost. Also, I'm pretty sure it should work over wifi although I am not sure if it will be the same with bluetooth (although most devices with BT have wifi now a days and you get more bandwidth)
I haven't tested this code so I'm not 100% sure it will work.
The next thing will be on the machine to transfer the audio into the desire app, but that's above my experience. I imagine you will have to do a virtual driver or something like that.
Also will have to do the inverse mechanism for the audio sent from the desktop app into the phone (I'm rather interested on that part since would make a nice wireless headset for watching movies as well).
Here are my 2 cents; I am eager to know if it works. ;)
s class of device to mimic a headset. This is just to connect over the hands-free profile. As far as sending the audio, etc., that is another challenge. I
m not sure that bluedroid even has support for this;you might need a custom kernel. – Metalloid