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

Duplex V2 API endpoint no longer works. #70

Closed michaelmnich closed 8 years ago

michaelmnich commented 8 years ago

This is my enabled speech API

image

I used GSpeechDuplex hello word example. This is my api code: AIzaSyB9-y0wdclhKNmi6nSzuCWGSCEFYmyncS0 (ill generate new one leater)

and this is my ERROR

Starting to write Error: 404 Exception in thread "Downstream Thread" java.lang.NullPointerException at com.darkprograms.speech.recognizer.GSpeechDuplex$1.run(GSpeechDuplex.java:197)

I don't know what im doing wrong can anyone give me a hint?

Skylion007 commented 8 years ago

Hmm, that's bizarre. For the record, based off of that status code, your error is not with the API key, but likely the format of data you trying to upload. For the record, it is not wise to upload binary files via the Duplex API (RecognizerV2 would probably be better). If it was an API key error, I believe it would be a 503 error.

Unfortunately, all I know is that Google is rejecting the file you uploaded for some reason and closing the downstream connection. Are you using the Microphone class or a binary file? Also ensure that you are having the Microphone encode the file as FLAC and not WAV.

Skylion007 commented 8 years ago

I just tested that specific API KEY and it does indeed work with my own internal demo code so your API key is absolutely fine and something else is causing the issue.

michaelmnich commented 8 years ago

HI thank you for respond :). Im not uploading any binary files. Im simply using your hello word example with microphone. And example from your page converts stream to flac. " Microphone mic = new Microphone(FLACFileWriter.FLAC);"

(code below).

public class Test01 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
     GSpeechDuplex dup = new GSpeechDuplex("AIzaSyB9-y0wdclhKNmi6nSzuCWGSCEFYmyncS0");
dup.addResponseListener(new GSpeechResponseListener(){// Adds the listener
    public void onResponse(GoogleResponse gr){
        System.out.println("Google thinks you said: " + gr.getResponse());
        System.out.println("with " + 
        ((gr.getConfidence()!=null)?(Double.parseDouble(gr.getConfidence())*100):null) 
            + "% confidence.");
        System.out.println("Google also thinks that you might have said:" 
                + gr.getOtherPossibleResponses());
    }
});
Microphone mic = new Microphone(FLACFileWriter.FLAC);//Instantiate microphone and have 
// it record FLAC file.
File file = new File("CRAudioTest.flac");//The File to record the buffer to. 
//You can also create your own buffer using the getTargetDataLine() method.
while(true){
    try{
        mic.captureAudioToFile(file);//Begins recording
        Thread.sleep(10000);//Records for 10 seconds
        mic.close();//Stops recording
        //Sends 10 second voice recording to Google
        byte[] data = Files.readAllBytes(mic.getAudioFile().toPath());//Saves data into memory.
                dup.recognize(data, (int)mic.getAudioFormat().getSampleRate());
        mic.getAudioFile().delete();//Deletes Buffer file
        //REPEAT
    }
    catch(Exception ex){
        ex.printStackTrace();//Prints an error if something goes wrong.
    }
}

}

}

Skylion007 commented 8 years ago

So apparently, I was using an old version of the library and the DuplexV2 endpoint is broken as you have indicated. I have reverted to the V1 endpoint now and pushed the changes. Try rebuilding the library at commit 0f7a0d38a6d5e990a0879ea8d340987b9a6b8a2a and see if that solves your issue. Meanwhile, I am going to try to figure out why the V1 endpoint has broken. @amplexus You were the one who switched the endpoint to the V2 endpoint, any ideas what could be going on?

Skylion007 commented 8 years ago

This was actually fixed a while ago, but I forgot to close the issue.