Guest User

Client Audio Input

a guest
Apr 29th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package client;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectOutputStream;
  5. import java.net.Socket;
  6.  
  7. import javax.sound.sampled.AudioFormat;
  8. import javax.sound.sampled.TargetDataLine;
  9.  
  10. public class ClientAudio implements Runnable {
  11.     private String ip;
  12.     private Socket s2;
  13.     private ObjectOutputStream o2;
  14.     private TargetDataLine microphone;
  15.     private AudioFormat audioformat;
  16.    
  17.     public ClientAudio(String ipAddress, TargetDataLine mic, AudioFormat af) {
  18.         ip = ipAddress;
  19.         microphone = mic;
  20.         audioformat = af;
  21.     }
  22.  
  23.     public void run() {
  24.         try {
  25.             s2 = new Socket(ip, 1210);
  26.             o2 = new ObjectOutputStream(s2.getOutputStream());
  27.             Thread car = new Thread(new ClientAudioRec(s2, audioformat));
  28.             car.start();
  29.             System.out.println("AUDIO");
  30.             int bytesRead = 0;
  31.             byte[] soundData = new byte[1];
  32.            
  33.             while(true) {
  34.                 bytesRead = microphone.read(soundData, 0, bytesRead);
  35.                 if(bytesRead >= 0) {
  36.                     o2.write(soundData, 0, bytesRead);
  37.                     o2.flush();
  38.                 }
  39.             }
  40.            
  41.         } catch (IOException e) {
  42.             e.printStackTrace();
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment