zgillis

Sound Client: Program.java

Jul 23rd, 2012
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.io.DataOutputStream;
  2. import java.net.*;
  3. import javax.sound.sampled.*;
  4.  
  5. public class Program
  6. {
  7.     public static void main(String[] args) throws Exception
  8.     {
  9.         AudioFormat af = new AudioFormat(8000.0f,8,1,true,false);
  10.         DataLine.Info info = new DataLine.Info(TargetDataLine.class, af);
  11.         TargetDataLine microphone = (TargetDataLine)AudioSystem.getLine(info);
  12.         microphone.open(af);
  13.         Socket conn = new Socket("localhost",3000);
  14.         microphone.start();
  15.         DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
  16.         int bytesRead = 0;
  17.         byte[] soundData = new byte[1];
  18.         Thread inThread = new Thread(new SoundReceiver(conn));
  19.         inThread.start();
  20.         while(bytesRead != -1)
  21.         {
  22.             bytesRead = microphone.read(soundData, 0, soundData.length);
  23.             if(bytesRead >= 0)
  24.             {
  25.                 dos.write(soundData, 0, bytesRead);
  26.             }
  27.         }
  28.         System.out.println("IT IS DONE.");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment