Streaming audio from Android to desktop application

Home - Streaming audio from Android to desktop application

Girly Saputri Staff asked 1 year ago

What the title says really. I need to stream the audio from the microphone on the telephone and play it in a desktop application (also Java code) on a computer.
Using UDP or TCP does not matter for me, whatever works best. Phone and computer will be on same NAT anyway so transmission will work fine.
I have a fair idea of how to send the stream data from the device using this code:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

String host = "10.0.2.2";
int port = 5740;

Socket socket = null;
try {
    socket = new Socket(InetAddress.getByName(host), port);

    ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
    recorder.setOutputFile(pfd.getFileDescriptor());
    recorder.prepare();
    recorder.start();

    Log.d(TAG, "Sending audio for 20 seconds..");
    Thread.sleep(20000);

    } catch (Exception e) {     
    // TODO Auto-generated catch block
        e.printStackTrace();
            }
Your Answer