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

1  
!7
2  
3  
p {
4  
  S text = or2(smartJoin(args), "hello");
5  
  print("TEXT: " + text);
6  
  
7  
  File mp3 = william_silent(text);
8  
  //try { playMp3(mp3); } catch {}
9  
  
10  
  File wavFile1 = prepareProgramFile("speech-big.wav");
11  
  File wavFile = prepareProgramFile("speech.wav");
12  
  
13  
  mp3ToWAV_2(mp3, wavFile1);
14  
  convertWAVForSphinx(wavFile1, wavFile);
15  
  
16  
  // direct conversion leads to robot voice bug
17  
  // convertWAVForSphinx(mp3, wavFile);
18  
  
19  
  
20  
  print("WAV: " + wavFile + " (" + wavFile.length() + ")");
21  
  pcall { playWAV(wavFile); }
22  
                                 
23  
  // Try to suppress logging
24  
  // java.util.logging.LogManager.getLogManager().reset(); // no workie
25  
  // java.util.logging.Logger.getLogger("global").setLevel(java.util.logging.Level.SEVERE);
26  
  java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.SEVERE);
27  
  
28  
  StreamSpeechRecognizer recognizer = makeSphinxRecognizer();
29  
30  
  print("Recognizing " + wavFile);
31  
32  
  new L<Long> times;
33  
  new L<S> lines;
34  
  for (int i = 0; i < 10; i++) {
35  
    long time = now();
36  
    recognizer.startRecognition(new FileInputStream(wavFile));
37  
    SpeechResult result;
38  
    print("loop");
39  
    lines = new L;
40  
    while ((result = recognizer.getResult()) != null) {
41  
      S line = result.getHypothesis();
42  
      lines.add(line);
43  
      print("Hypothesis: " + line);
44  
    }
45  
    print("done");
46  
    recognizer.stopRecognition();
47  
    times.add(now()-time);
48  
  }
49  
  
50  
  print("Recognition times: " + struct(times));
51  
  
52  
  S recognized = trim(fromLines(lines));
53  
  print("recognized: " + recognized);
54  
  if (match(text, recognized))
55  
    print("perfect match!!!");
56  
  else {
57  
    print("not quite.");
58  
    print("input was: " + text);
59  
  }
60  
}

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: 723 / 772
Version history: 9 change(s)
Referenced in: [show references]