我可以帮您进行翻译。以下是翻译的结果,保留了原有的HTML标签:
我编写了一个从客户端到服务器通过TCP流传输音频的应用程序,但是它不起作用,也就是说没有可听的输出。您能否检查我的代码并告诉我哪里出了问题?
客户端:
public void startStreaming() {
Thread streamThread = new Thread(new Runnable() {
@Override
public void run() {
try {
int minBufSize =AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
Log.d("VD ", "Bufer intioalised "+minBufSize);
short[] buffer=new short[minBufSize];
Log.d("VS","Buffer created of size .c" + minBufSize);
// DatagramPacket packet;
final InetAddress destination = InetAddress.getByName(target.getText().toString());
port=Integer.parseInt(target_port.getText().toString());
Socket socket=new Socket(destination,port);
DataOutputStream dos=new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
Log.d("VS", "Address retrieved.c");
if (minBufSize != AudioRecord.ERROR_BAD_VALUE) {
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRate,channelConfig,audioFormat,minBufSize);
Log.d("VS", "Recorder initialized.c");}
if (recorder.getState() == AudioRecord.STATE_INITIALIZED){
Log.d("VS", "Recorder working....c");
recorder.startRecording();}
BufferedWriter input;
while(status == true) {
//reading data from MIC into buffer
int bufferReadResult = recorder.read(buffer, 0, buffer.length);
dos.write(buffer,0,bufferReadResult);
dos.flush();
}
} catch(UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
Log.e("IOException message:",e.getMessage().toString());
}
}
服务器:
public void startStreaming() { Thread streamThread = new Thread(new Runnable() {
开始流媒体传输:
public void startStreaming() { Thread streamThread = new Thread(new Runnable() {
@Override
public void run() {
try {
int minBufSize =1024;//recorder.getMinBufferSize(sampleRate,channelConfig,audioFormat);
ServerSocket serversocket = new ServerSocket(50005);
// DatagramSocket socket = new DatagramSocket(50005);
byte[] buffer = new byte[1024];
if (minBufSize != AudioRecord.ERROR_BAD_VALUE) {
speaker = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,channelConfig,audioFormat,minBufSize,AudioTrack.MODE_STREAM);
speaker.play();
Log.d("VR", "spekaer playing...");
}
// }
Log.d("VR", ""+status);
BufferedReader input;
InputStream is;
ObjectInputStream ois;
ByteArrayInputStream baiss;
socket = serversocket.accept();
DataInputStream dis=new DataInputStream(new BufferedInputStream(socket.getInputStream()));
while(status == true) {
//DatagramPacket packet = new DatagramPacket(buffer,buffer.length);
InputStream in = socket.getInputStream();
Log.d("content :", socket.getOutputStream().toString());
int i=0;
while (dis.available() > 0 && i < buffer.length) {
buffer[i]=(byte) dis.readShort();
i++;
}
speaker.write(buffer,0,buffer.length);
请给我您最好的帮助。
(这是您需要翻译的内容)