Giter Club home page Giter Club logo

lkuza2 / java-speech-api Goto Github PK

View Code? Open in Web Editor NEW
531.0 98.0 304.0 433 KB

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.

License: GNU General Public License v3.0

Java 100.00%
java speech-recognition speech speech-synthesis speech-to-text jarvis api google recognition

java-speech-api's Introduction

J.A.R.V.I.S. (Java-Speech-API)

J.A.R.V.I.S. Java Speech API: Just A Reliable Vocal Interpreter & Synthesizer. This is a project for the Java Speech API. The program interprets vocal inputs into text and synthesizes voices from text input. The program supports dozens of languages and even has the ability to auto-detect languages!

Description

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.

Features

The API currently provides the following functionality,

  • Microphone Capture API (Wrapped around the current Java API for simplicity)
  • A speech recognizer using Google's recognizer service
    • Converts WAVE files from microphone input to FLAC (using existing API, see CREDITS)
    • Retrieves Response from Google, including confidence score and text
  • A speech synthesiser using Google's synthesizer service
    • Retrieves synthesized text in an InputStream (MP3 data ready to be played)
  • Wave to FLAC API (Wrapped around the used API in the project, javaFlacEncoder, see CREDITS)
  • A translator using Google Translate (courtesy of Skylion's Google Toolkit)

Notes

To get access to the Google API, you need an API key. To get this, you need to follow the instructions here:

A sample application using this library can be found here:

  • See API-Example repository branch.

Changelog

See CHANGELOG.markdown for Version History/Changelog

Credits

See CREDITS.markdown for Credits

java-speech-api's People

Contributors

adamukaapan avatar allanhasegawa avatar amplexus avatar clusterm avatar cweiske avatar dean1510 avatar duncanj avatar karloscampus avatar skylion007 avatar tartinjs avatar xingrz avatar yakeb avatar yehorchenkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-speech-api's Issues

Hello World Duplex

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.

main

hi, if I could get a sample main class that translates speech to text?

NegativeArraySizeException

Hi !

I use your api in my Siri like app : Asilane.
I've modified a little bit your program but sometimes an exception is throwed :
java.lang.NegativeArraySizeException
at com.darkprograms.speech.recognizer.FlacEncoder.convertWaveToFlac(FlacEncoder.java:57)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:70)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:94)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:155)

I'm using the java-speech-api dowloaded this summer.

passive listening wont work

hey! am new and i been using your libraries to build my own speech system. now i want to implement the passive listening but it seems not work cause it uses the old recognizer (V1). would you help me to repair the code? if you have any solution or option for me it will be great.

thx for your work

Duplex Hello World example

Byte[] data = Files.read(mic.getAudioFile());//Saves data into memory.

Which class does this "Files" belong to? I use NetBeans IDE, and it's suggesting me Files.ReadAllBytes (which requires a Path, not a File).

Synthesizer gives 403 error when getting MP3 Data

java.io.IOException: Server returned HTTP response code: 403 for URL: http://translate.google.com/translate_a/t?client=thello+world

You should look into this.

Code:

String language = "auto";
Synthesiser synth = new Synthesiser(language);
try {
InputStream is = synth.getMP3Data(output);
AudioStream audioStream = new AudioStream(is);
AudioPlayer.player.start(audioStream);
//TODO Use any Java MP3 Implementation to play back the AudioFile from the InputStream.
}
catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("Error");
e.printStackTrace();
return;
}

main

hi, if I could get a sample main class that translates speech to text?

Language support

I want to know the language support by this API?

Can it support Hindi language or other Indian languages?

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

Regrettably, my Java skills are rusty and here is my code:

public class SpeechTest {
public static void main(String[] args){
GSpeechDuplex dup = new GSpeechDuplex(AI....Q0); //--Abbreviated API key--
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.
        }
    }
}

}

Here are my errors:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
AI....Q0 cannot be resolved to a variable
The method getOtherPossibleResponses() is undefined for the type GoogleResponse
The method getAudioFormat() from the type Microphone is not visible

at SpeechTest.main(SpeechTest.java:12)

Any assistance would be much appreciated.

Thanks,
Shaun

Text to speech issue:

Text to speech queries longer than 100 characters thrown an exception (probably because Google ignores the request). I've implemented a work around text parser in my code that breaks the query into multiple smaller queries, but it would by nice to implement something like this in the synthesiser.getMP3Data(String) method automatically.

Suggestion to stream audio to GoogleSpeechAPI

Just making a suggestion that you could increase the efficiency of your program by streaming audio directly to GoogleSpeechAPIv2. Below is a working nodejs proof-of-concept. I'm still trying to make a Python variant. And I'm looking forward to trying your project on a RaspberryPi.

var request = require("request");
var rec = require('node-record-lpcm16');
rec.start({
sampleRate : 16000,
verbose : true
}).pipe(request.post({
'url' : 'https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=apikeyhere',
'headers' : {
'Content-Type' : 'audio/l16; rate=16000;'
}
}, exports.parseResult));
}

The google API has been closed now ?

I try curl on my mac:

curl -v -X POST \
--data-binary @speech.flac \
--user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7' \
--header 'Content-Type: audio/x-flac; rate=8000;' \
'https://www.google.com/speech-api/v1/recognize?client=chromium&lang=zh-CN&maxresults=10' 

It never works but return as below:

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 500 (Server Error)!!1</title>
  <style>
   ...
  </style>
  <a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
  <p><b>500.</b> <ins>Thatโ€™s an error.</ins>
  <p>The server encountered an error and could not complete your request.
<p>If the problem persists, please 
<A HREF="http://www.google.com/support/">report</A> 
your problem and mention this error message and the query that caused it.
  <ins>Thatโ€™s all we know.</ins>

does anyone have the same problem?

Error when creating the FLAC

When running the FLAC encoder on a local version of this file: http://buggerluggs.tripod.com/wavs/hello.wav
I get this exception:
java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Buffer.java:478)
at java.nio.HeapByteBuffer.getShort(HeapByteBuffer.java:285)
at com.darkprograms.speech.recognizer.FlacEncoder.convertWaveToFlac(FlacEncoder.java:66)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:28)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:41)
at net.datao.stt.DoItAll$3.actionPerformed(DoItAll.java:48)

Do you have that same problem on the same file?

Dependencies?

Hey Shadow, this project looks insanely cool! Unfortunately, I can't figure out what the dependency is for all the FLAC-related stuff, as I am being given a bunch of "Can't find this class" errors from Netbeans. If you could tell me (and potentially add it to the README) that would be great!

Thanks for putting cool things like this on gh :)

Getting 500 back on wav mono 16000

Hi,

I am trying to send 30 sec of 16000 of wav files by using the flak getRecognizedDataForWave

But google seends back a 500. Do you have any ide what this can be?

Thanks

cool wrapper you built

Unable to contact google

I am trying to run the helloworld example of this library, but am unable to do so as making requests to google is failing. Following is the error stack-trace:
ERROR: Google cannot be contacted
java.io.FileNotFoundException: https://www.google.com/speech-api/v1/recognize&lang=en-US&maxresults=4
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1624)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.darkprograms.speech.recognizer.Recognizer.rawRequest(Recognizer.java:456)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForFlac(Recognizer.java:271)
at helloWorld.main(helloWorld.java:38)

This is failing within the Recognizer.java in the following code
br = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), Charset.forName("UTF-8")));

Is there an alternate way of making this work - like using the V2 of Speech to Text api?

java.io.FileNotFoundException: AudioTestNow.flac (The requested operation cannot be performed on a file with a user-mapped section open)

When following this tutorial that you have written, but slightly modified to use the V2 speech API (GSpeechDuplex) instead of the V1 API shown in the tutorial, I get this error: java.io.FileNotFoundException: AudioTestNow.flac (The requested operation cannot be performed on a file with a user-mapped section open)
No line is given that is inside my code. However, it still gets a response from the server (and is correct).

The modified code from the tutorial:

GSpeechDuplex dup = new GSpeechDuplex(API_KEY);
dup.addResponseListener((GoogleResponse gr) ->
{
    displayResponse(gr);
});
dup.recognize(mic.getAudioFile(), (int)mic.getAudioFormat().getSampleRate());

In case you want it, here's the full log:

java.io.FileNotFoundException: AudioTestNow.flac (The requested operation cannot be performed on a file with a user-mapped section open)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:213)
at java.io.FileOutputStream.(FileOutputStream.java:162)
at javaFlacEncoder.FLACFileOutputStream.(FLACFileOutputStream.java:53)
at javaFlacEncoder.FLACFileWriter.write(FLACFileWriter.java:102)
at javax.sound.sampled.AudioSystem.write(AudioSystem.java:1356)
at com.darkprograms.speech.microphone.Microphone$CaptureThread.run(Microphone.java:228)
at java.lang.Thread.run(Thread.java:745)

Let me know if you need any more information.

Exception 400

Tried to run the recognizer on a simple .wav file and get:
java.io.IOException: Server returned HTTP response code: 400 for URL: https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&maxresults=1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.darkprograms.speech.recognizer.Recognizer.rawRequest(Recognizer.java:421)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:221)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:240)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:291)
The calling code is very simple. What am I missing? Could running from Eclipse on a Mac be a problem?
public static void main(String[] args) {
Recognizer rec=new Recognizer();
GoogleResponse resp = null;
try {
resp = rec.getRecognizedDataForWave(testWaveFile);
} catch (Exception e) {
e.printStackTrace();
}
String text = resp.getResponse();
System.out.println(text);

}

could not write audio file....

I keep getting following error message with helloworld example

Recording...
java.lang.IllegalArgumentException: could not write audio file: file type not supported: FLAC
at javax.sound.sampled.AudioSystem.write(AudioSystem.java:1363)
at com.darkprograms.speech.microphone.Microphone$CaptureThread.run(Microphone.java:216)
at java.lang.Thread.run(Thread.java:744)
Recording stopped.
ERROR: Google cannot be contacted
java.io.FileNotFoundException: testfile2.flac (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:146)
at com.darkprograms.speech.recognizer.Recognizer.rawRequest(Recognizer.java:444)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForFlac(Recognizer.java:271)
at helloWorld.main(helloWorld.java:43)

Add authentication failure callback

Thanks for your great API. It works perfectly!
But! If I set a wrong API key or no API key there is an exception thrown in the http thread...
Exception in thread "Downstream Thread"
java.lang.NullPointerException
com.darkprograms.speech.recognizer.GSpeechDuplex$1.run(GSpeechDuplex.java:197)

Can you enable a possibility to catch it via callback for example?

Google cannot be contacted: getting null response

Hi,

Since it has been suggested (sorry for being off-topic the other day), I'm opening my own issue about a connectivity problem I'm encountering with Google servers.

Here is what I'm woking with:

  • Current version of J.A.R.V.I.S
  • Hello World test class I got from the Wiki section of this same repo

I've mostly tried step-by-step debugging on the "rawRequest" method in Recognizer.java, to see if it came from the request building part (especially when encoding FLAC data), still no clue.

  1. The built request URL is the following (nothing fancy here, I just kept default parameters) :
    https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US&maxresults=4
  2. I can only guess that up to when outputStream has read fileInput data (and it is properly encoded) things are going great (but i'm not familiar with dealing with streams and HTTP requests in Java). Plus, I can see data written in outputStream.buf.
  3. The part where things get wrong must be around when the BufferedReader getting the InputStream, because then I get... a null br. Also, when the response string reads this br, it becomes null.

I hope this info can help solving my case, if you need to know more about a particular point, please ask me!

As I've been told recently, even if Google has in the meantime (silently) released a v2 of its speech API, the "old" one should still work, so I'm really clueless now, after trying a few hours to understand why my attempts keep failing.

Any hints or help would be greatly appreciated :)

Not working for me?

Hi,

here is my code:

public static void main(String[] args){
        GSpeechDuplex dup = new GSpeechDuplex("AS***********************Fto");//Instantiate the API
        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(AudioFileFormat.Type.WAVE);//Instantiate microphone and have 
        // it record FLAC file.
        File file = new File("CRAudioTest.wav");//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(5000);//Records for 10 seconds
                mic.close();//Stops recording
                //Sends 10 second voice recording to Google
                Path path = Paths.get("CRAudiotest.wav");
                byte[] data = Files.readAllBytes(path);//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.
            }
        }
    }

I replaced the Flac with the wav files, because it threw me an error that FLACFileWriter wasn't there.
Basically what the log says:
Starting to write
IO WRITE DONE
Finished write on down stream...

And this goes on in a loop.

I also tried another method:

private static void ambientListening() throws Exception{

        String filename = "tarunaudio.wav";//Your Desired FileName
        MicrophoneAnalyzer mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
        mic.open();
        System.out.println("start talking.");
        mic.captureAudioToFile(filename);
        Thread.sleep(3000);
        mic.close();
        System.out.println("stop talking");
        FlacEncoder encoder = new FlacEncoder();
        encoder.convertWaveToFlac(filename, "newfilename.flac");

        try {
        RecognizerChunked rec = new RecognizerChunked("************************************"); //this is the api key I blurred out
        GoogleResponse googleResponse = rec.getRecognizedDataForFlac("newfilename.flac", 8000);
        System.out.println(googleResponse.getResponse());
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

The code above gives me the error that getRecognizedDataForFlac should return in GoogleResponse, but in the method it won't return anything.

(I'm quite new to Java and OOP)

Language Support

This great project!, I wonder if it has support for recognition in Spanish. Thank you

Main method.

Hi, I can't seem to find the main method for the API?

java.net.SocketException: Connection reset - Any solution apart from disabling of antivirus to resolve this exception ?

I am trying to create an application that employs speech to text recognition. In order to better understand the Shadow API, I ran the sample application. The application runs successfully. But what I found was that upon running, it successfully converts speech to text the first time, but subsequent attempts to convert speech to text result in java.net.SocketException . This happens each time I run the application.

The exception gets thrown when the method getOutputStream() is called in Recognizer.java.

Here is the full stack trace.

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at com.darkprograms.speech.recognizer.Recognizer.rawRequest(Recognizer.java:209)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:38)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:67)
at com.darkprograms.speech.recognizer.Recognizer.getRecognizedDataForWave(Recognizer.java:130)
at com.shadow.testing.Main$3.actionPerformed(Main.java:41)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

On searching the internet I found that one of the causes for this kind of behavior can be the antivirus program. So I disabled my antivirus. And on disabling the antivirus, the application works perfectly. It does not throw java.net.SocketException at all.

So one solution for this issue can be disabling of antivirus.

But I cannot expect the user of my application to disable his/her antivirus program to be able to use my application. And even after a lot of research I am not able to find any solution apart from this.

Could anyone guide me as to what can be done to not get the exception, apart from disabling the antivirus. Any help would be highly appreciated.

Speech Recognition API (V1) discontinued. Switch to V2

It appears as though the V1 Speech Recognition API has been discontinued (the URL is generating 400 error). In the meantime, please use the V2 Duplex and chunked APIs instead. We are working on solving this issue ASAP.

404 That's an error

Hello,

unfortunately I can't get your api to work =(

https://www.google.com/speech-api/full-duplex/v2/ only gives me a 404, as well as the GSpeechDuplex class:

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 joined the chromium group and created a key: Speech API 15.10.2015 Server AIzaSy....

Any help is greatly appreciated!

Regards,
Dustin

Missing class AePlayWave.java in Util

Hi,
I'm working on a plugin using your old GUI adapted for my need. In the last changes the class AePlayWave.java is no more available. Is it possible to include it again on the repo?
Thanks
Mauro

Multiple mics, source choose

Good day!
Is it possible to use multiple microphones in the library?
How do I know which device is produced capture sound?

Incorrect code in Hello World

    GoogleResponse response = recognizer.getRecognizedDataForFlac(file, maxNumOfResponses);

This is an invalid line because the class recognizer.getRecognizedDataForFlac doesn't exist.

Netbeans IDE 7.3, JDK 7.

The app don't recognize my mic

Hello guy!
I could compile the example that you provided. I have no problems with de synthesiser, but on the other hand, the app don't recognize the microphone of my notebook.

captura

Do you have an idea about the problem??
I compiled it on Eclipse (maybe here is the problem), in Windows 7.
Thanks!!!

Dependencies?

Hey Shadow, this project looks insanely cool! Unfortunately, I can't figure out what the dependency is for all the FLAC-related stuff, as I am being given a bunch of "Can't find this class" errors from Netbeans. If you could tell me (and potentially add it to the README) that would be great!

Thanks for putting cool things like this on gh :)

Hello World Duplex delivers NullPointerException

I ran my program with administrator access so that Windows allows mic access to the program. (Windows 8.1 x64) 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();
}                                 

So why is it behaving like that?

First test -> failure.

I wrote this simple code to test your lib:

package net.datao.stt;

import com.darkprograms.speech.microphone.Microphone;
import com.darkprograms.speech.recognizer.Recognizer;

import javax.sound.sampled.AudioFileFormat;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**

  • Created by IntelliJ IDEA.

  • User: lolive

  • Date: 23/06/12

  • Time: 00:03

  • To change this template use File | Settings | File Templates.
    */
    public class DoItAll extends JFrame {
    JButton stop = new JButton("Stop");
    JButton run = new JButton("Run");
    JButton process = new JButton("Process");
    Microphone microphone = new Microphone(AudioFileFormat.Type.WAVE);
    Recognizer recognizer = new Recognizer();
    String audioFile = "c:/temp/toto.wav";

    public DoItAll(){
    stop.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    microphone.close();
    }
    });
    run.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {

                microphone.captureAudioToFile(audioFile);
            } catch (Exception e1) {
                e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                JOptionPane.showMessageDialog(null, e1.getMessage());
            }
        }
    });
    process.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String response = "error";
            try {
                response = recognizer.getRecognizedDataForWave(audioFile).getResponse();
            } catch (Exception e1) {
                e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                response = e1.getMessage();
            }
            JOptionPane.showMessageDialog(null, response);
        }
    });
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
    getContentPane().add(run);        
    getContentPane().add(stop);
    getContentPane().add(process);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    show();
    

    }

    public static void main(String[] args) {
    new DoItAll();
    }

}

It show a JFrame, you click "Run", you talk in the micro, you stop talking, you click "Stop" and then click "Process". And then a JOptionPane shows the google response.
Easy.
But I get this rawResponse from Google:
{"status":5,"id":"5ea8848cad8489a332c589dcfaa14af4-1","hypotheses":[]}
and my code ends with an exception.

Did I miss something?
Or did Google change something that breaks java-speech-api ?

Streaming Audio directly to the Duplex API

Hi, thank you for your work. It works well. But I would like to use the streaming audio with Dpulex API. I do not see any class called MicDuplex.java in your project. Where can I get it ?

Thank you

Hello World Duplex

I'm very sorry, I'm completely new to programming and am currently taking a class in Java, I'm just trying to get the Hello World example running but I'm having a problem on this line:

Byte[] data = Files.read(mic.getAudioFile());//Saves data into memory.
dup.recognize(data, (int)mic.getAudioFormat().getSampleRate());

getting the following error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method read(InputStream, int) in the type Files is not applicable for the arguments (File)
The method recognize(File, int) in the type GSpeechDuplex is not applicable for the arguments (Byte[], int)

at com.darkprograms.speech.Main.main(Main.java:43)]

Please let me know what I'm doing wrong here, I'm pretty sure I've set everything up correctly

New GitHub release

Would it be possible to create a new GitHub release containing the latest working source code?
I seem to be unable to build the repository from the current source code, as I can not resolve the project's dependencies.
Perhaps it might be worth looking into setting up Apache Maven with this project, in which case I could definitely help setup dependency management.

Thankyou,
psgs ๐ŸŒด

Hello World Duplex not working for me

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?

RecognizerChunked can not parse result correctly

RecognizerChunked's parseResponse function paser fellow response

{"result":[{"alternative":[{"transcript":"This is a apple","confidence":0.97342438},{"transcript":"This is a apple"},{"transcript":"This is a apple"}],"final":true}],"result_index":0}

Making 0.97342438 as element of otherPossibleResponses ArrayList, result as

Google thinks you said: This is a apple
with 97.342438% confidence.
Google also thinks that you might have said:[0.97342438, This is a apple, This is a apple]

I would like to adapt java-json to parse raw response

    /**
     * Parses the response into a Google Response
     * @param rawResponse The raw String you want to parse
     * @param gr The GoogleResponse you want to parse into ti.
     */
    private void parseResponse(String rawResponse, GoogleResponse gr){
        if(rawResponse == null || !rawResponse.contains("\"result\"")){ return; }

        JSONObject object = new JSONObject(rawResponse);
        JSONObject result = object.getJSONArray("result").getJSONObject(0);
        JSONArray ASRHypotheses = result.getJSONArray("alternative");
        String response = "";
        String confidence = "";
        if (ASRHypotheses.length() == 1) {
            //  Google is 100% confident in it's translation
            response = ASRHypotheses.getJSONObject(0).getString("transcript");
            if (ASRHypotheses.getJSONObject(0).has("confidence")) {
                confidence = String.valueOf(ASRHypotheses.getJSONObject(0).getDouble("confidence"));
            }
            else {
                confidence = String.valueOf(1d);
            }
        }
        else {
            String otherResponse;
            for (int i = 0; i < ASRHypotheses.length(); i++) {
                if (i == 0) {
                    response = ASRHypotheses.getJSONObject(i).getString("transcript");
                    confidence = String.valueOf(ASRHypotheses.getJSONObject(i).getDouble("confidence"));
                } else {
                    System.out.println(ASRHypotheses.getJSONObject(i));
                    otherResponse = ASRHypotheses.getJSONObject(i).getString("transcript");
                    gr.getOtherPossibleResponses().add(otherResponse);
                }
            }
        }
        gr.setResponse(response);
        gr.setConfidence(confidence);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.