Android AudioRecord to Server over UDP Playback Issues

前端 未结 2 652
野趣味
野趣味 2020-12-12 17:06

I am trying to make a simple Android application that streams live microphone audio to a server for playback. The resulting playback sounds strange, with large gaps in the a

2条回答
  •  时光说笑
    2020-12-12 17:34

    Here's something you could try, instead of:

    // read the data into the buffer
    recorder.read(buffer, 0, buffer.length);
    
    // place contents of buffer into the packet
    packet = new DatagramPacket(buffer, buffer.length, serverAddress, PORT);
    

    Do not expect you received fully read buffer from recorder but use actual read value instead

    // read the data into the buffer
    int read = recorder.read(buffer, 0, buffer.length);
    
    // place contents of buffer into the packet
    packet = new DatagramPacket(buffer, read, serverAddress, PORT);
    

    Or something alike.

提交回复
热议问题