audio - Detecting sound from microphone using Java. Issue with Java Versions -


i'm running simple code listens microphone , prints out bytes.

problem: listens microphone changes correctly on java version "1.6.0_43"

but doesn't listen microphone changes correctly on java version "1.7.0_25"

code compiles , runs fine on both versions.

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 drops down around 2500 that's when there sound going 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 noise 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;                     (int = 0; < 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?

also posted on these forums, no luck =(

http://www.coderanch.com/t/615528//java/detecting-sound-microphone-java-java#2811088

http://www.dreamincode.net/forums/topic/324610-detecting-sound-from-microphone-using-java-issue-with-java-versions/


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -