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

52
LINES

< > BotCompany Repo | #1004788 // Test Sphinx4 (Speech Recognition)

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

Uses 36468K of libraries. Click here for Pure Java version (1474L/11K/34K).

1  
!752
2  
3  
lib 1004789 // sphinx core
4  
lib 1004793 // sphinx data
5  
6  
import edu.cmu.sphinx.api.Configuration;
7  
import edu.cmu.sphinx.api.SpeechResult;
8  
import edu.cmu.sphinx.api.StreamSpeechRecognizer;
9  
10  
p {
11  
  S text = or2(smartJoin(args), "hello");
12  
  print("TEXT: " + text);
13  
  
14  
  File mp3 = william_silent(text);
15  
  File wavFile1 = prepareProgramFile("speech-big.wav");
16  
  File wavFile = prepareProgramFile("speech.wav");
17  
  mp3ToWAV(mp3, wavFile1);
18  
  convertWAVForSphinx(wavFile1, wavFile);
19  
  print("WAV: " + wavFile + " (" + wavFile.length() + ")");
20  
                                 
21  
  new Configuration configuration;
22  
23  
  configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
24  
  configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
25  
  configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
26  
27  
  StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
28  
  
29  
  print("Recognizing " + wavFile);
30  
  InputStream stream = new FileInputStream(wavFile);
31  
32  
  recognizer.startRecognition(stream);
33  
  SpeechResult result;
34  
  print("loop");
35  
  new L<S> lines;
36  
  while ((result = recognizer.getResult()) != null) {
37  
    S line = result.getHypothesis();
38  
    lines.add(line);
39  
    print("Hypothesis: " + line);
40  
  }
41  
  print("done");
42  
  recognizer.stopRecognition();
43  
  
44  
  S recognized = trim(fromLines(lines));
45  
  print("recognized: " + recognized);
46  
  if (match(text, recognized))
47  
    print("perfect match!!!");
48  
  else {
49  
    print("not quite.");
50  
    print("input was: " + text);
51  
  }
52  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004788
Snippet name: Test Sphinx4 (Speech Recognition)
Eternal ID of this version: #1004788/1
Text MD5: b42793eb9dd49683580d2398eac14f28
Transpilation MD5: 29d6543a9328916d679c60e871d06507
Author: stefan
Category: javax / speech
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-31 15:05:34
Source code size: 1620 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 610 / 686
Referenced in: [show references]