Hello there!
I'm running this simple code that listens to my microphone and prints out bytes.
Problem:
It listens to the microphone for any changes correctly on
java version "1.6.0_43"
but it doesn't listen to the microphone for any changes correctly on
java version "1.7.0_25"
Both version compile and run fine.
Example Output using Java 1.6
5172 1
5196 2
5103 3
2859 4
2549 5
2742 6
3112 7
5028 8
4515 9
3856 10
5189 11
5080 12
5165 13
4925 14
When it drops down to around 2500 that's when there was sound going into the microphone.
Example Output using Java 1.7
5652 1
5655 2
5699 3
6081 4
6213 5
5972 6
5907 7
5828 8
5931 9
6187 10
6015 11
5949 12
6196 13
It no longer detects any noise from the microphone.
import java.io.*; import javax.sound.sampled.*; public class SpeechDetectionTest { public static void main(String[] args) { ByteArrayOutputStream byteArrayOutputStream; TargetDataLine targetDataLine; int cnt; boolean stopCapture = false; byte tempBuffer[] = new byte[8000]; int countzero, countdownTimer; short convert[] = new short[tempBuffer.length]; try { byteArrayOutputStream = new ByteArrayOutputStream(); stopCapture = false; countdownTimer = 0; while (!stopCapture) { AudioFormat audioFormat = new AudioFormat(8000.0F, 16, 1, true, false); DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat); targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo); targetDataLine.open(audioFormat); targetDataLine.start(); cnt = targetDataLine.read(tempBuffer, 0, tempBuffer.length); byteArrayOutputStream.write(tempBuffer, 0, cnt); try { countzero = 0; for (int i = 0; i < tempBuffer.length; i++) { convert[i] = tempBuffer[i]; if (convert[i] == 0) { countzero++; } } countdownTimer++; System.out.println(countzero + " " + countdownTimer); } catch (StringIndexOutOfBoundsException e) { System.out.println(e.getMessage()); } Thread.sleep(0); targetDataLine.close(); } } catch (Exception e) { System.out.println(e); } } }
Any ideas?