Android: Streaming audio over TCP Sockets

前端 未结 3 1387
小蘑菇
小蘑菇 2021-01-31 10:40

For my app, I need to record audio from MIC on an Android phone, and send it over TCP to the other android phone, where it needs to be played.

I am using AudioReco

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 10:51

    I got this working, with some help, and only partially.

    I started off with the code at http://emeadev.blogspot.com/2009/09/raw-audio-manipulation-in-android.html, changed File's streams to Socket's streams, and changed the isAvailable() to if(inputStream.read(byteArray) != -1).

    Live streaming of audio over TCP is happening now.

    However,

    All I hear at the other end is noise, and I am now hunting for correct set of parameters for AudioRecorder and AudioTrack - the frequency, channel config and encoding, audio source etc.

    If you have any idea about this, please let me know.

    Thanks,

    EDIT: It was a stupid error on my part. In addition to all I have said above, use inputStream on player side and outputStream on recorder side, and byte arrays instead of shorts and it will work. :)

提交回复
热议问题