Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

74
LINES

< > BotCompany Repo | #1015719 // Test JARVIS API (Java Speech Toolkit) - doesn't work with Google anymore...

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Transpiled version (5326L) is out of date.

!7

lib 1015718 // JARVIS
lib 1015720 // FLAC encoder
lib 1015721 // JSON

import javax.sound.sampled.AudioFileFormat.Type;
import javax.sound.sampled.*;
import net.sourceforge.javaflacencoder.FLACFileWriter;

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

 /**
   * Jarvis Speech API Tutorial
   * @author Aaron Gokaslan (Skylion)
   *
   */

p {
  fixContextClassLoader();

  // Mixer.Info[] infoArray = AudioSystem.getMixerInfo();
  // for(Mixer.Info info : infoArray) {
  //    print("info: " + info.toString());
  // } 
  AudioFileFormat.Type[] typeArray = AudioSystem.getAudioFileTypes();
  for (AudioFileFormat.Type type : typeArray) {
     print("type: " + type.toString());
  } 

  Microphone mic = new Microphone(FLACFileWriter.FLAC);
  File file = prepareProgramFile("testfile2.flac");	//Name your file whatever you want
  try {
    mic.captureAudioToFile (file);
  } catch (Exception ex) {
    //Microphone not available or some other error.
    print("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.
   */
  pcall {
    print("Recording...");
    sleep(5000);	//In our case, we'll just wait 5 seconds.
    mic.close();
  }

  mic.close();		//Ends recording and frees the resources
  print("Recording stopped.");

  Recognizer recognizer = new Recognizer (Recognizer.Languages.ENGLISH_US, youTubeDataAPIKey());
  //Although auto-detect is available, it is recommended you select your region for added accuracy.
  try {
    int maxNumOfResponses = 4;
    print("Sample rate is: " + (int) mic.getAudioFormat().getSampleRate());
    GoogleResponse response = recognizer.getRecognizedDataForFlac (file, maxNumOfResponses, (int) mic.getAudioFormat().getSampleRate ());
    print ("Google Response: " + response.getResponse ());
    print ("Google is " + Double.parseDouble (response.getConfidence ()) * 100 + "% confident in" + " the reply");
    print("Other Possible responses are: ");
    for (String s : response.getOtherPossibleResponses ())
      printIndent(s);
  }
  catch (Exception ex) {
    // TODO Handle how to respond if Google cannot be contacted
    print("ERROR: Google cannot be contacted");
    ex.printStackTrace ();
  }

  file.deleteOnExit ();	//Deletes the file as it is no longer necessary.
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1015719
Snippet name: Test JARVIS API (Java Speech Toolkit) - doesn't work with Google anymore...
Eternal ID of this version: #1015719/7
Text MD5: 03f91079feb37a7db270317313350754
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-25 02:08:16
Source code size: 2593 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 865 / 1519
Version history: 6 change(s)
Referenced in: