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

60
LINES

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

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

Uses 36492K of libraries. Click here for Pure Java version (2986L/20K/64K).

!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);
  
  StreamSpeechRecognizer recognizer = makeSphinxRecognizer();

  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("Recognition times: " + 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 #1004788

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004801
Snippet name: Test Sphinx4 Speech Recognizer With Synthesized Voice (William) [WORKS]
Eternal ID of this version: #1004801/10
Text MD5: 195cb8ffab25e8cea5a6dcd1fde4ed62
Transpilation MD5: b4b0ed7a4d0f2fc5cc0483637ba05989
Author: stefan
Category: javax / speech
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-24 14:39:33
Source code size: 1725 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 655 / 685
Version history: 9 change(s)
Referenced in: [show references]