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

62
LINES

< > BotCompany Repo | #1006994 // Test Sphinx4 Speech Recognizer With Synthesized Voice (William) [faster, WORKS]

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

Uses 36492K of libraries. Click here for Pure Java version (3034L/21K/65K).

!7

p {
  S text = or2(smartJoin(args), "hello");
  print("TEXT: " + text);
  
  File mp3 = william_silent(text);
  //try { playMp3(mp3); } catch {}
  
  File wavFile1 = prepareProgramFile("speech-big.wav");
  File wavFile = prepareProgramFile("speech.wav");
  
  mp3ToWAV_2(mp3, wavFile1);
  convertWAVForSphinx(wavFile1, wavFile);
  
  // direct conversion leads to robot voice bug
  // convertWAVForSphinx(mp3, wavFile);
  
  
  print("WAV: " + wavFile + " (" + wavFile.length() + ")");
  pcall { playWAV(wavFile); }
                                 
  // Try to suppress logging
  // java.util.logging.LogManager.getLogManager().reset(); // no workie
  // java.util.logging.Logger.getLogger("global").setLevel(java.util.logging.Level.SEVERE);
  java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.SEVERE);
  
  long loadTime = sysNow();
  StreamSpeechRecognizer2 recognizer = new StreamSpeechRecognizer2(makeSphinxConfig());
  loadTime = sysNow()-loadTime;

  print("Recognizing " + wavFile);

  new L<Long> times;
  new L<S> lines;
  for (int i = 0; i < 10; i++) {
    long time = now();
    recognizer.startRecognition(new FileInputStream(wavFile));
    SpeechResult result;
    print("loop");
    lines = new L;
    while ((result = recognizer.getResult()) != null) {
      S line = result.getHypothesis();
      lines.add(line);
      print("Hypothesis: " + line);
    }
    print("done");
    recognizer.stopRecognition();
    times.add(now()-time);
  }
  
  print("Loading time: " + loadTime + ". Recognition times (ms): " + struct(times));
  
  S recognized = trim(fromLines(lines));
  print("recognized: " + recognized);
  if (match(text, recognized))
    print("perfect match!!!");
  else {
    print("not quite.");
    print("input was: " + text);
  }
}

Author comment

Began life as a copy of #1004801

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: #1006994
Snippet name: Test Sphinx4 Speech Recognizer With Synthesized Voice (William) [faster, WORKS]
Eternal ID of this version: #1006994/9
Text MD5: 271f526281119d33f5499cb47d036227
Transpilation MD5: 426ed1eb490cfdf8b33eb0248e08559a
Author: stefan
Category: javax / speech
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-26 00:18:27
Source code size: 1850 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 602 / 730
Version history: 8 change(s)
Referenced in: [show references]