Uses 39910K of libraries. Click here for Pure Java version (4540L/31K/109K).
!7 static JButton button; static volatile Capturer cap; static File wavFile; static Q recognizerQueue; static StreamSpeechRecognizer2 recognizer; p-substance { showControls(jCenteredLine(button = jbutton("Record!", f recordOrStop))); recognizerQueue = new Q("Recognizer Queue", true); recognizerQueue.add(r { infoBox("Loading engine..."); recognizer = new StreamSpeechRecognizer2(makeSphinxConfig()); infoBox("Engine loaded!"); }); } svoid recordOrStop { if (cap != null) { cap.stop(); byte[] pcm = cap.getPCM(); infoMessage("Got " + l(pcm) + " bytes PCM!"); pcmToWAVE(pcm, cap.format(), wavFile); infoBox("Wrote " + f2s(wavFile) + " (" + wavFile.length() + " bytes)"); cap = null; setText(button, "Record!"); recognizeAudio(wavFile); } else { AudioLine line = first(allTargetDataLines()); assertNotNull("Need audio input line!", line); DataLine dataLine = cast line.open(); print("Capturing"); wavFile = prepareProgramFile(ymd_minus_hms() + ".wav"); cap = captureAudioFromLine2(dataLine, sphinxAudioFormat()); setText(button, "Stop"); } } svoid recognizeAudio(final File wavFile) { recognizerQueue.add(r { loading { recognizer.startRecognition(new FileInputStream(wavFile)); SpeechResult result; print("Recognizing audio..."); S line = null; while ((result = recognizer.getResult()) != null) { line = result.getHypothesis(); print(" Hypothesis: " + line); } print("Done recognizing"); infoBox("You said: " + line); recognizer.stopRecognition(); } }); }
Began life as a copy of #1007035
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: | #1007039 |
Snippet name: | Capture Audio By Button Press & Recognize With CMU Sphinx [WORKS!] |
Eternal ID of this version: | #1007039/5 |
Text MD5: | df04b413c9e50bf670d288f53e23a0a5 |
Transpilation MD5: | 62b70171589fbe00df185daa88560e13 |
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 00:31:20 |
Source code size: | 1681 bytes / 56 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 496 / 622 |
Version history: | 4 change(s) |
Referenced in: | #1007047 - Your voice -> wit.ai -> Kevin [WORKS with wit.ai token] |