Warning: session_start(): open(/var/lib/php/sessions/sess_m2rk5nsnq9pgss61pg6vrp7aai, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!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.
}