lkuza2 / java-speech-api

The J.A.R.V.I.S. Speech API is designed to be simple and efficient, using the speech engines created by Google to provide functionality for parts of the API. Essentially, it is an API written in Java, including a recognizer, synthesizer, and a microphone capture utility. The project uses Google services for the synthesizer and recognizer. While this requires an Internet connection, it provides a complete, modern, and fully functional speech API in Java.
GNU General Public License v3.0
535 stars 301 forks source link

Hello World Duplex not working for me #49

Closed mayukhnair closed 10 years ago

mayukhnair commented 10 years ago
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:513)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:121)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:153)
at com.darkprograms.speech.microphone.Microphone.open(Microphone.java:191)
at com.darkprograms.speech.microphone.Microphone$CaptureThread.run(Microphone.java:227)
at java.lang.Thread.run(Thread.java:744)

Do note that no other application is using the microphone right now.

Here is my code:

 Thread MicInputThread=new Thread(new Runnable(){
        public void run(){
            duplo.addResponseListener(new GSpeechResponseListener(){
                public void OnResponse(GoogleResponse googres){
                    String parsedtext=googres.getResponse();
                    System.out.println(parsedtext);
                }

                @Override
                public void onResponse(GoogleResponse gr) {
                    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                }
            });
            micra=new Microphone(FLACFileWriter.FLAC);
            audiofil=new File("AudioTest.flac");
            while(true){
                try{
                    micra.captureAudioToFile(audiofil);
                    Thread.sleep(5000);
                    micra.close();
                    byte[] data=Files.readAllBytes(micra.getAudioFile().toPath());
                    duplo.recognize(data, (int)micra.getAudioFormat().getSampleRate());
                    micra.getAudioFile().delete();
                }
                catch (Exception ex){
                    ex.printStackTrace();
                }
            }
        }
    });
   MicInputThread.start();
}                                        

Is it possible that this line of code byte[] data=Files.readAllBytes(micra.getAudioFile().toPath()); may be the culprit?

Skylion007 commented 10 years ago

No, the line unavailable yada yada means there is something wrong microphone on your device. The JVM cannot access. Either you are trying to access in a blocking manner from multiple threads or it's not properly detected or something along those lines. It has nothing to do with the Speech API's underlying code except maybe in the Microphone class. Your microphone may also just not support the required format in which case you will need to tweak the audio format settings in the Microphone class.