Streaming Real time Audio

后端 未结 1 1410
轻奢々
轻奢々 2021-01-02 11:33

I want to have a functionality of real time audio streaming on android device which is capturing audio through the MIC of the device and send it to the server. I know to sen

相关标签:
1条回答
  • 2021-01-02 12:10

    You can use sockets as so:

    String hostname = "1.2.3.4";
    int port = 865;
    
    Socket socket = null;
    
    try {
        socket = new Socket(InetAddress.getByName(hostname), port);
    } catch (Exception e) {
    
        e.printStackTrace();
    }
    
    ParcelFileDescriptor socketedFile = ParcelFileDescriptor.fromSocket(socket);
    

    Then set the socketedFile to the output file (socketedFile.getFileDescriptor()) of the audio recorder. This will send it up as bytes.

    Alternatively to make it more stable, write out the data from the MediaRecorder to a local buffer and then have a separate thread check that buffer and write it to the socket instead, to allow for small disconnections in the socket connection.

    See this question for more information: android stream audio to server

    Obviously you then need to have an application running on a server to receive your bytes and turn that into audio data.

    0 讨论(0)
提交回复
热议问题