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).

!752

lib 1004789 // sphinx core
lib 1004793 // sphinx data

import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.SpeechResult;
import edu.cmu.sphinx.api.StreamSpeechRecognizer;

p {
  S text = or2(smartJoin(args), "hello");
  print("TEXT: " + text);
  
  File mp3 = william_silent(text);
  File wavFile1 = prepareProgramFile("speech-big.wav");
  File wavFile = prepareProgramFile("speech.wav");
  mp3ToWAV(mp3, wavFile1);
  convertWAVForSphinx(wavFile1, wavFile);
  print("WAV: " + wavFile + " (" + wavFile.length() + ")");
                                 
  new Configuration configuration;

  configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
  configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
  configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");

  StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
  
  print("Recognizing " + wavFile);
  InputStream stream = new FileInputStream(wavFile);

  recognizer.startRecognition(stream);
  SpeechResult result;
  print("loop");
  new L<S> lines;
  while ((result = recognizer.getResult()) != null) {
    S line = result.getHypothesis();
    lines.add(line);
    print("Hypothesis: " + line);
  }
  print("done");
  recognizer.stopRecognition();
  
  S recognized = trim(fromLines(lines));
  print("recognized: " + recognized);
  if (match(text, recognized))
    print("perfect match!!!");
  else {
    print("not quite.");
    print("input was: " + text);
  }
}

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: 608 / 683
Referenced in: [show references]