diff --git a/.gitignore b/.gitignore index ef5c2b5..8f01f4f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 -.idea # User-specific stuff: .idea/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ee12254 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..64840c0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/CRAudioTest.flac b/CRAudioTest.flac new file mode 100644 index 0000000..56e1a56 Binary files /dev/null and b/CRAudioTest.flac differ diff --git a/JARVIS-API.jar b/JARVIS-API.jar new file mode 100644 index 0000000..bfe96a3 Binary files /dev/null and b/JARVIS-API.jar differ diff --git a/java-json.jar b/java-json.jar new file mode 100755 index 0000000..2f211e3 Binary files /dev/null and b/java-json.jar differ diff --git a/javaFlacEncoder-0.3.1.jar b/javaFlacEncoder-0.3.1.jar new file mode 100644 index 0000000..636191c Binary files /dev/null and b/javaFlacEncoder-0.3.1.jar differ diff --git a/src/com/company/DuplexMain.java b/src/com/company/DuplexMain.java new file mode 100644 index 0000000..6e0eb12 --- /dev/null +++ b/src/com/company/DuplexMain.java @@ -0,0 +1,46 @@ +package com.company; + +import com.darkprograms.speech.microphone.Microphone; +import com.darkprograms.speech.recognizer.GSpeechDuplex; +import com.darkprograms.speech.recognizer.GSpeechResponseListener; +import com.darkprograms.speech.recognizer.GoogleResponse; +import javaFlacEncoder.FLACFileWriter; + +import java.io.File; +import java.nio.file.Files; + +public class DuplexMain { + + public static void main(String[] args) { + + GSpeechDuplex dup = new GSpeechDuplex("AIzaSyDMRFZsdncfP2udmTbozAQ2owJuL5RRm34");//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(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(5000);//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. + } + } + } +} \ No newline at end of file diff --git a/src/com/company/Main.java b/src/com/company/Main.java new file mode 100644 index 0000000..a730351 --- /dev/null +++ b/src/com/company/Main.java @@ -0,0 +1,75 @@ +package com.company; + +import javax.sound.sampled.AudioFileFormat.Type; +import javax.sound.sampled.*; +import java.io.File; + +import com.darkprograms.speech.microphone.Microphone; +import com.darkprograms.speech.recognizer.Recognizer; +import com.darkprograms.speech.recognizer.GoogleResponse; +import javaFlacEncoder.FLACFileWriter; + +/** + * Jarvis Speech API Tutorial + * @author Aaron Gokaslan (Skylion) + * + */ +public class Main { + + public static void main (String[]args) { + + // Mixer.Info[] infoArray = AudioSystem.getMixerInfo(); + // for(Mixer.Info info : infoArray) { + // System.out.println("info: " + info.toString()); + // } + AudioFileFormat.Type[] typeArray = AudioSystem.getAudioFileTypes(); + for(AudioFileFormat.Type type : typeArray) { + System.out.println("type: " + type.toString()); + } + + Microphone mic = new Microphone(FLACFileWriter.FLAC); + File file = new File ("/tmp/testfile2.flac"); //Name your file whatever you want + try { + mic.captureAudioToFile (file); + } catch (Exception ex) { + //Microphone not available or some other error. + System.out.println ("ERROR: Microphone is not availible."); + ex.printStackTrace (); + } + + /* User records the voice here. Microphone starts a separate thread so do whatever you want + * in the mean time. Show a recording icon or whatever. + */ + try { + System.out.println ("Recording..."); + Thread.sleep (5000); //In our case, we'll just wait 5 seconds. + mic.close (); + } catch (InterruptedException ex) { + ex.printStackTrace (); + } + + mic.close (); //Ends recording and frees the resources + System.out.println ("Recording stopped."); + + Recognizer recognizer = new Recognizer (Recognizer.Languages.ENGLISH_US, "AIzaSyDMRFZsdncfP2udmTbozAQ2owJuL5RRm34"); + //Although auto-detect is available, it is recommended you select your region for added accuracy. + try { + int maxNumOfResponses = 4; + System.out.println("Sample rate is: " + (int) mic.getAudioFormat().getSampleRate()); + GoogleResponse response = recognizer.getRecognizedDataForFlac (file, maxNumOfResponses, (int) mic.getAudioFormat().getSampleRate ()); + System.out.println ("Google Response: " + response.getResponse ()); + System.out.println ("Google is " + Double.parseDouble (response.getConfidence ()) * 100 + "% confident in" + " the reply"); + System.out.println ("Other Possible responses are: "); + for (String s:response.getOtherPossibleResponses ()) { + System.out.println ("\t" + s); + } + } + catch (Exception ex) { + // TODO Handle how to respond if Google cannot be contacted + System.out.println ("ERROR: Google cannot be contacted"); + ex.printStackTrace (); + } + + file.deleteOnExit (); //Deletes the file as it is no longer necessary. + } +} \ No newline at end of file diff --git a/test_google_speach_api.iml b/test_google_speach_api.iml new file mode 100644 index 0000000..b3bd4b0 --- /dev/null +++ b/test_google_speach_api.iml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file