1515import javax .sound .sampled .TargetDataLine ;
1616
1717import com .deb .vad .utility .CommonUtil ;
18+ import org .slf4j .Logger ;
19+ import org .slf4j .LoggerFactory ;
1820
1921/**
2022 * @author debmalyajash
@@ -28,6 +30,8 @@ public class SilenceDetector implements SoundCache{
2830 private static final int ARRAY_SIZE = 8 ;
2931 public static byte [] SILENCE = new byte [ARRAY_SIZE ];
3032
33+ private static final Logger logger = LoggerFactory .getLogger (SilenceDetector .class );
34+
3135 public static void main (final String args []) {
3236 Thread .currentThread ().setName ("DebSilenceDetector" );
3337 AudioFormat format = CommonUtil .getAudioFormat ();
@@ -80,16 +84,19 @@ public static void main(final String args[]) {
8084 Arrays .fill (SILENCE , (byte ) 0 );
8185 ais .read (b , 0 , size );
8286
83- // System.out.println( System.currentTimeMillis() );
87+
8488 if (Arrays .equals (SILENCE , b )) {
85- // System.out.println("AS");
89+ if (logger .isInfoEnabled ()){
90+ logger .info ("~~~ SILENCE ~~~~" );
91+ }else {
92+ System .out .println ("~~~ SILENCE ~~~~" );
93+ }
8694 } else {
87- // timeBasedAudioInputMap.put(System.currentTimeMillis(), b);
88- // System.out.println("W");
89- System .out .println ( System .currentTimeMillis () );
90- System .out .println ( b .length );
91- // System.out.println( "NS" );
92- System .out .println ( Arrays .toString ( b ) );
95+ if (logger .isInfoEnabled ()){
96+ logger .info (String .format ("~~~ NOISE ~~~~ %s" ,Arrays .toString ( b )));
97+ }else {
98+ System .out .println (String .format ("~~~ NOISE ~~~~ %s" ,Arrays .toString ( b )));
99+ }
93100 }
94101
95102 // The AudioSystem class provides methods for reading and
@@ -100,7 +107,9 @@ public static void main(final String args[]) {
100107
101108 }
102109 } catch (Throwable e ) {
103- e .printStackTrace ();
110+ if (logger .isInfoEnabled ()){
111+ logger .error (e .getMessage (),e );
112+ }
104113 } finally {
105114 if (line != null ) {
106115 line .flush ();
0 commit comments