Uses 16925K of libraries. Click here for Pure Java version (5055L/34K/119K).
1 | !7 |
2 | |
3 | static JButton button; |
4 | static volatile Capturer cap; |
5 | static File wavFile; |
6 | static Q recognizerQueue; |
7 | |
8 | p-substance { |
9 | showControls(jCenteredLine(button = jbutton("Record!", f recordOrStop))); |
10 | recognizerQueue = new Q("Recognizer Queue", true); |
11 | thread { kevin(""); } // init speech synthesizer |
12 | } |
13 | |
14 | svoid recordOrStop { |
15 | if (cap != null) { |
16 | cap.stop(); |
17 | byte[] pcm = cap.getPCM(); |
18 | infoMessage("Got " + l(pcm) + " bytes PCM!"); |
19 | pcmToWAVE(pcm, cap.format(), wavFile); |
20 | //infoBox("Wrote " + f2s(wavFile) + " (" + wavFile.length() + " bytes)"); |
21 | cap = null; |
22 | setText(button, "Record!"); |
23 | recognizeAudio(wavFile); |
24 | } else { |
25 | AudioLine line = first(allTargetDataLines()); |
26 | assertNotNull("Need audio input line!", line); |
27 | DataLine dataLine = cast line.open(); |
28 | print("Capturing"); |
29 | wavFile = prepareProgramFile(ymd_minus_hms() + ".wav"); |
30 | cap = captureAudioFromLine2(dataLine, sphinxAudioFormat()); |
31 | setText(button, "Stop"); |
32 | } |
33 | } |
34 | |
35 | svoid recognizeAudio(final File wavFile) { |
36 | recognizerQueue.add(r { |
37 | loading { |
38 | print("Recognizing audio..."); |
39 | /*File mp3File = new File(wavFile.getPath() + ".mp3"); |
40 | wavToMP3(wavFile, mp3File);*/ |
41 | S line = witAI_recognizeWAV(wavFile); |
42 | print("Done recognizing"); |
43 | infoBox("You said: " + line); |
44 | |
45 | kevin(line); // repeat what user said |
46 | } |
47 | }); |
48 | } |
Began life as a copy of #1007039
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: | #1007047 |
Snippet name: | Your voice -> wit.ai -> Kevin [WORKS with wit.ai token] |
Eternal ID of this version: | #1007047/11 |
Text MD5: | fdac5974d46aeea7695035a277b35b2a |
Transpilation MD5: | deae880e42d36588f4112a3b15e11519 |
Author: | stefan |
Category: | javax / audio |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-02-26 15:25:32 |
Source code size: | 1418 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 519 / 632 |
Version history: | 10 change(s) |
Referenced in: | [show references] |