对于我的应用程序,我需要在Android手机上录制来自MIC的音频,并通过TCP将其发送到另一个需要播放的android手机。Android:通过TCP套接字流式音频
我使用的是AudioRecord
和AudioTrack
类。这对于文件非常有用 - 使用DataOutputStream
将文件写入文件,并使用DataInputStream
从文件中读取。
但是,如果我从套接字而不是文件获得相同的流,并尝试写入它,我会得到一个异常。
我不知道什么可能会出错。任何帮助将不胜感激。
编辑:问题是相同的,即使我尝试使用较大的缓冲区大小(65535字节,160000字节)。
这是代码:
记录:
int bufferSize = AudioRecord.getMinBufferSize(11025, , AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
AudioRecord recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
byte[] tempBuffer = new byte[bufferSize];
recordInstance.startRecording();
while (/*isRecording*/) {
bufferRead = recordInstance.read(tempBuffer, 0, bufferSize);
dataOutputStreamInstance.write(tempBuffer);
}
上面得到的是DataOutputStream为:
BufferedOutputStream buff = new BufferedOutputStream(out1); //out1 is the socket's outputStream
DataOutputStream dataOutputStreamInstance = new DataOutputStream (buff);
可否请你看看,让我知道它是什么我可能在这里做错了?
感谢,
您是否设法将音频文件发送到其他设备? – B770 2013-08-07 09:40:54