Download Jar. Transpiled version (5326L) is out of date.
1 | !7 |
2 | |
3 | lib 1015718 // JARVIS |
4 | lib 1015720 // FLAC encoder |
5 | lib 1015721 // JSON |
6 | |
7 | import javax.sound.sampled.AudioFileFormat.Type; |
8 | import javax.sound.sampled.*; |
9 | import net.sourceforge.javaflacencoder.FLACFileWriter; |
10 | |
11 | import com.darkprograms.speech.microphone.Microphone; |
12 | import com.darkprograms.speech.recognizer.Recognizer; |
13 | import com.darkprograms.speech.recognizer.GoogleResponse; |
14 | |
15 | /** |
16 | * Jarvis Speech API Tutorial |
17 | * @author Aaron Gokaslan (Skylion) |
18 | * |
19 | */ |
20 | |
21 | p { |
22 | fixContextClassLoader(); |
23 | |
24 | // Mixer.Info[] infoArray = AudioSystem.getMixerInfo(); |
25 | // for(Mixer.Info info : infoArray) { |
26 | // print("info: " + info.toString()); |
27 | // } |
28 | AudioFileFormat.Type[] typeArray = AudioSystem.getAudioFileTypes(); |
29 | for (AudioFileFormat.Type type : typeArray) { |
30 | print("type: " + type.toString()); |
31 | } |
32 | |
33 | Microphone mic = new Microphone(FLACFileWriter.FLAC); |
34 | File file = prepareProgramFile("testfile2.flac"); //Name your file whatever you want |
35 | try { |
36 | mic.captureAudioToFile (file); |
37 | } catch (Exception ex) { |
38 | //Microphone not available or some other error. |
39 | print("ERROR: Microphone is not availible."); |
40 | ex.printStackTrace (); |
41 | } |
42 | |
43 | /* User records the voice here. Microphone starts a separate thread so do whatever you want |
44 | * in the mean time. Show a recording icon or whatever. |
45 | */ |
46 | pcall { |
47 | print("Recording..."); |
48 | sleep(5000); //In our case, we'll just wait 5 seconds. |
49 | mic.close(); |
50 | } |
51 | |
52 | mic.close(); //Ends recording and frees the resources |
53 | print("Recording stopped."); |
54 | |
55 | Recognizer recognizer = new Recognizer (Recognizer.Languages.ENGLISH_US, youTubeDataAPIKey()); |
56 | //Although auto-detect is available, it is recommended you select your region for added accuracy. |
57 | try { |
58 | int maxNumOfResponses = 4; |
59 | print("Sample rate is: " + (int) mic.getAudioFormat().getSampleRate()); |
60 | GoogleResponse response = recognizer.getRecognizedDataForFlac (file, maxNumOfResponses, (int) mic.getAudioFormat().getSampleRate ()); |
61 | print ("Google Response: " + response.getResponse ()); |
62 | print ("Google is " + Double.parseDouble (response.getConfidence ()) * 100 + "% confident in" + " the reply"); |
63 | print("Other Possible responses are: "); |
64 | for (String s : response.getOtherPossibleResponses ()) |
65 | printIndent(s); |
66 | } |
67 | catch (Exception ex) { |
68 | // TODO Handle how to respond if Google cannot be contacted |
69 | print("ERROR: Google cannot be contacted"); |
70 | ex.printStackTrace (); |
71 | } |
72 | |
73 | file.deleteOnExit (); //Deletes the file as it is no longer necessary. |
74 | } |
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: | 864 / 1518 |
Version history: | 6 change(s) |
Referenced in: | [show references] |