import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import java.math.*; import javax.sound.sampled.*; public class main { public static void main(String[] args) throws Exception { new Client().captureAudio(); } static class Client { boolean stopCapture = false; AudioFormat audioFormat; TargetDataLine targetDataLine; BufferedOutputStream out = null; BufferedInputStream in = null; Socket sock = null; private void captureAudio() { try { /*sock = new Socket("192.168.1.5", 500); out = new BufferedOutputStream(sock.getOutputStream()); in = new BufferedInputStream(sock.getInputStream());*/ Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo(); for (int i = 0; i < l(mixerInfo); i++) { print("Mixer " + i + ": " + mixerInfo[i]); Line.Info[] lines = AudioSystem.getMixer(mixerInfo[i]).getTargetLineInfo(); for (int j = 0; j < l(lines); j++) print(" Target line " + j + ": " + lines[j]); lines = AudioSystem.getMixer(mixerInfo[i]).getSourceLineInfo(); for (int j = 0; j < l(lines); j++) print(" Source line " + j + ": " + lines[j]); print(); } audioFormat = getAudioFormat(); Mixer mixer = AudioSystem.getMixer(mixerInfo[5]); /*DataLine.Info dataLineInfo = new DataLine.Info( TargetDataLine.class, audioFormat);*/ Line.Info dataLineInfo = mixer.getTargetLineInfo()[0]; targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo); targetDataLine.open(audioFormat); targetDataLine.start(); Thread captureThread = new CaptureThread(); captureThread.start(); } catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }} class CaptureThread extends Thread { byte tempBuffer[] = new byte[10000]; @Override public void run() { stopCapture = false; try { while (!stopCapture) { int cnt = targetDataLine.read(tempBuffer, 0, tempBuffer.length); //out.write(tempBuffer); //print("Bytes received: " + tempBuffer.length); print("min=" + min(tempBuffer) + ", max=" + max(tempBuffer)); } } catch (Exception e) { System.out.println(e); System.exit(0); } } } private AudioFormat getAudioFormat() { float sampleRate = 8000.0f; int sampleSizeInBits = 8; int channels = 1; boolean signed = true; boolean bigEndian = false; return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian); } } static volatile StringBuffer local_log = new StringBuffer(); // not redirected static volatile StringBuffer print_log = local_log; // might be redirected, e.g. to main bot // in bytes - will cut to half that static volatile int print_log_max = 1024*1024; static volatile int local_log_max = 100*1024; static void print() { print(""); } // slightly overblown signature to return original object... static A print(A o) { String s = String.valueOf(o) + "\n"; StringBuffer loc = local_log; StringBuffer buf = print_log; int loc_max = print_log_max; if (buf != loc && buf != null) { print_append(buf, s, print_log_max); loc_max = local_log_max; } if (loc != null) print_append(loc, s, loc_max); System.out.print(s); return o; } static void print(long l) { print(String.valueOf(l)); } static void print_append(StringBuffer buf, String s, int max) { synchronized(buf) { buf.append(s); max /= 2; if (buf.length() > max) try { int newLength = max/2; int ofs = buf.length()-newLength; String newString = buf.substring(ofs); buf.setLength(0); buf.append("[...] ").append(newString); } catch (Exception e) { buf.setLength(0); } } } static int min(int a, int b) { return Math.min(a, b); } static double min(double[] c) { double x = Double.MAX_VALUE; for (double d : c) x = Math.min(x, d); return x; } static byte min(byte[] c) { byte x = 127; for (byte d : c) if (d < x) x = d; return x; } static int max(int a, int b) { return Math.max(a, b); } static long max(int a, long b) { return Math.max((long) a, b); } static long max(long a, long b) { return Math.max(a, b); } static double max(int a, double b) { return Math.max((double) a, b); } static int max(Collection c) { int x = Integer.MIN_VALUE; for (int i : c) x = max(x, i); return x; } static double max(double[] c) { if (c.length == 0) return Double.MIN_VALUE; double x = c[0]; for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]); return x; } static byte max(byte[] c) { byte x = -128; for (byte d : c) if (d > x) x = d; return x; } static int l(Object[] array) { return array == null ? 0 : array.length; } static int l(byte[] array) { return array == null ? 0 : array.length; } static int l(int[] array) { return array == null ? 0 : array.length; } static int l(char[] array) { return array == null ? 0 : array.length; } static int l(Collection c) { return c == null ? 0 : c.size(); } static int l(Map m) { return m == null ? 0 : m.size(); } static int l(String s) { return s == null ? 0 : s.length(); } }