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
534 stars 301 forks source link

Hello World Duplex #51

Closed mayukhnair closed 9 years ago

mayukhnair commented 10 years ago
java.lang.IllegalArgumentException: No line matching interface TargetDataLine supporting format PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian is supported.
at javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:479)
at com.darkprograms.speech.microphone.Microphone.initTargetDataLine(Microphone.java:105)
at com.darkprograms.speech.microphone.Microphone.<init>(Microphone.java:96)
at Client$32.run(Client.java:1060)
at java.lang.Thread.run(Thread.java:744)

I dunno what this is.

Skylion007 commented 10 years ago

You're testing machine doesn't have access to a microphone... -_- In other words, the Java Virtual Machine cannot access the microphone...

On Tue, Oct 14, 2014 at 12:02 PM, mayukhnair notifications@github.com wrote:

java.lang.IllegalArgumentException: No line matching interface TargetDataLine supporting format PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian is supported. at javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:479) at com.darkprograms.speech.microphone.Microphone.initTargetDataLine(Microphone.java:105) at com.darkprograms.speech.microphone.Microphone.(Microphone.java:96) at Client$32.run(Client.java:1060) at java.lang.Thread.run(Thread.java:744)

I dunno what this is.

— Reply to this email directly or view it on GitHub https://github.com/The-Shadow/java-speech-api/issues/51.

mayukhnair commented 10 years ago

Hi, did some tests to find out the culprit.

Apparently, this is turning out to be a platform-specific issue.

On Windows XP Professional, the program can access the microphone; however, it delivers a NullPointerException and "ERROR". Which is funny, since I tested the mic and it's working nicely with other programs. Note that no other program is using the microphone. The LineUnavailableException issue is occuring only with Windows 8.1.

I'm an amateur programmer with little idea about what is happening and why. Please forgive my stupid queries and assist me.

mayukhnair commented 10 years ago

Another thing: I understand the duplex example is for continuous recognition. But, just like the original "Hello World", I want the process to shut down after running just once ie. I want just one-time recognition. Is there any way I can tell the Duplex method to run only once, or can I modify the original Hello World example to use the API key provided, if possible?

Skylion007 commented 9 years ago

You can also close the microphone when you are done recording. Keep in mind that you do not want to it to stop once it receives one input as this will input will likely be a single utterance such as "The" or something along those lines. Instead, have a Thread.sleep() close the microphone and hence the data stream to the duplex api when you have computed the desired response.

mayukhnair commented 9 years ago

Welcome back after a long hiatus :)

And thanks for the previous advice. But as I told you in the previous message, there is a platform issue as well: my Java VM (JDK 8 64-bit) does not allow access to microphone at all in Windows 8.1. The Recognizer is working on XP, but it keeps delivering a NullPointerException. Mic seems to work perfectly, and I ran a program with the older version of the API to check mic access. The FLAC file had recorded my voice, so now there is no issue of mic access. So what is the problem here? Why the NullPointer?

Skylion007 commented 9 years ago

What type of null pointer? I need something more specific if I am to be of help in this matter.

mayukhnair commented 9 years ago

Really sorry for going offline. On the Windows 8.1 PC which gave me the LineUnavailableException, I finally ran java using Administrator access to see the issues. This is what I got:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Windows\system32>java -jar "C:\Users\nairm_000\Documents\NetBeansProjects\DOSRocket (Git)\DOSRocket\DOSRocket (Git)\dist\DOSRocket.jar"
Exception in thread "Thread-6" java.lang.UnsupportedOperationException: Not supported yet.
  at Client$34$1.onResponse(Client.java:1103)
    at com.darkprograms.speech.recognizer.GSpeechDuplex.fireResponseEvent(GSpeechDuplex.java:356)
    at com.darkprograms.speech.recognizer.GSpeechDuplex.access$2(GSpeechDuplex.java:354)
    at com.darkprograms.speech.recognizer.GSpeechDuplex$1.run(GSpeechDuplex.java:147)

Code for recognizer is as follows:

 import com.darkprograms.speech.microphone.Microphone;
 import com.darkprograms.speech.recognizer.GSpeechDuplex;
 import com.darkprograms.speech.recognizer.GSpeechResponseListener;
 import com.darkprograms.speech.recognizer.GoogleResponse; 
 GSpeechDuplex duplo=new GSpeechDuplex(<private api key>);
 Microphone micra;
 File audiofil;
 Thread MicInputThread=new Thread(new Runnable(){
        public void run(){
            duplo.addResponseListener(new GSpeechResponseListener(){
                public void OnResponse(GoogleResponse googres){
                    String parsedtext=googres.getResponse();
                    resp.setText(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();
}