我正在尝试将麦克风输入数据流式传输到将在其扬声器上输出流的 PC。流应该被压缩然后加密。
我尝试了以下方法:
安卓手机:
AudioGroup audioGroup = new AudioGroup();
audioGroup.setMode(AudioGroup.MODE_NORMAL);
AudioStream audioStream = new AudioStream(InetAddress.getLocalHost());
int port = audioStream.getLocalPort();
// tell other side which port to use (this works)
daos.writeInt(port);
audioStream.setCodec(AudioCodec.PCMU);
audioStream.setMode(RtpStream.MODE_SEND_ONLY);
audioStream.associate(adr, port);
audioStream.join(audioGroup);
AudioManager Audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Audio.setMode(AudioManager.MODE_IN_COMMUNICATION);
接收方的 Java 程序。如何使用 UDP 套接字进行传输?
DatagramSocket datagramSocket = new DatagramSocket(port);
System.out.println("Waiting for audio data...");
source = AudioSystem.getAudioInputStream(????.getInputStream());
AudioSystem.getAudioInputStream(AudioFormat.Encoding.ULAW, source);
byte[] audioData = new byte[4096];
source.read(audioData, 0, 4096);
toSpeaker(audioData);
我希望有人能帮助我。当然,任何其他想法都值得赞赏。